接搜狗SDK,調login接口報錯:Must be called from main thread of process

問題

接搜狗SDK,調login接口報錯

java.lang.IllegalStateException: Must be called from main thread of process

解決辦法

Looper.getMainLooper()就表示放到主UI線程去處理

Handler handler = new Handler(Looper.getMainLooper());
class MyThread implements Runnable {
	@Override
	public void run() { 
		// TODO 搜狗login    
    }
}
handler.post(new MyThread());
Looper.loop();

也可以使用runOnUiThread,如下

m_context.runOnUiThread(new Runnable() {
	@Override
	public void run() { 
		// TODO 搜狗login    
    }
});

搜狗SDK文檔

http://open.wan.sogou.com/doc/offline-sdk.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章