1. 程式人生 > >安卓開發異常rx.exceptions.OnErrorNotImplementedException: Must be called from main thread of fragment host

安卓開發異常rx.exceptions.OnErrorNotImplementedException: Must be called from main thread of fragment host

rx.exceptions.OnErrorNotImplementedException: Must be called from main thread of fragment host

異常提示:必須在主執行緒中執行
異常描述:我在執行某個操作時出現的異常,類似跳轉到首頁等的頁面跳轉
異常解決方案:建立一個執行緒,在建立的執行緒裡面執行原來想要執行的程式碼,new 一個handler呼叫post傳送訊息
private Handler handler = new Handler(Looper.getMainLooper());
class MyThread implements Runnable {
public void run() { 
    //原來想要執行的程式碼
    }
}
handler.post(new MyThread());//呼叫方法傳送訊息(原來想要執行的地方)