public void onMessageReceived(RemoteMessage remoteMessage) {
try {
String type=remoteMessage.getData().get("type");
if(type.equals("1001")) {
CommonClass common = new CommonClass(getApplication());
CommonClass.MyTaskSendLog.execute(getApplicationContext(), DeviceDetails,lines);
}
} catch (Exception ex) {
}
}
此代码给出错误:
Method execute must be called from the main thread, currently inferred thread is worker
最佳答案
我想你的方法在服务中。
要访问服务中的 UI 线程(主线程),您必须创建一个处理程序并在其中调用方法,如下所示:
if(type.equals("1001")) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
CommonClass common = new CommonClass(getApplication());
CommonClass.MyTaskSendLog.execute(getApplicationContext(), DeviceDetails,lines);
}
});
}
您可以在服务的onCreate
中创建Handler。
关于android - webmethod 不调用 firebase 通知 onMessageReceived 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38454122/