小编Joh*_*ohn的帖子

Toast"在死线程上向处理程序发送消息"

我试图通过Toast显示一条简单的消息,并得到一个RunTime Exception"在死线程上向Handler发送消息".尝试显示Toast消息的类扩展了IntentService.该类(C2DMReceiver)实际上来自C2DM的ChromeToPhone示例.这是方法:

/**
 * Called when a cloud message has been received.
 */
@Override
public void onMessage(Context context, Intent intent) {
    Log.i(LOG_TAG, "A message notification has occured with the cloud.");

        Log.i(LOG_TAG, "Showing toast message of the broadcast...");
        Toast toast = Toast.makeText(context, "Some text", Toast.LENGTH_LONG);
        toast.show();

        Log.i(LOG_TAG, "Sending notification of the broadcast...");
        LauncherUtils.generateNotification(this, "this is where the text would go.", "Broadcast", intent);

    }
}
Run Code Online (Sandbox Code Playgroud)

我假设因为类扩展了IntentService,所以可以通过这种方式从这里请求一个简单的Toast消息.这不对吗?

android

20
推荐指数
4
解决办法
1万
查看次数

标签 统计

android ×1