gpt4 book ai didi

android - webmethod 不调用 firebase 通知 onMessageReceived 方法

转载 作者:行者123 更新时间:2023-11-29 19:42:20 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com