我正在尝试通过Toast显示一个简单的消息,但是遇到了运行时异常“在已经停止的线程上向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);
}
}
我认为由于这个类扩展了IntentService,应该可以通过这种方式在这里请求一个简单的Toast消息。这不正确吗?