【发布时间】:2013-03-25 08:34:40
【问题描述】:
这是我的代码,当收到推送通知时,我必须在 AsyncTask 中执行一些 http 请求。 据我了解,如果我需要在推送通知到达时执行某些操作,我必须在 OnMessage() 方法中执行此操作。 但是,应用程序在收到通知时崩溃并且不执行我需要它执行的操作: 代码:
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
String message = intent.getExtras().getString("price");
//sends info to the server
new PostAsyncTask().execute();
displayMessage(context, message);
// notifies user
generateNotification(context, message);
}
非常感谢! (如果你需要全班直接说出来。不过我可以告诉你 PostAsyncTask 执行一些 httpRequest 代码。)
Logcat:
异步任务: (它只是调用一个执行一些http请求的函数)
class PostAsyncTask extends AsyncTask<String, Integer, Boolean> {
protected Boolean doInBackground(String... params) {
ReNewCoordinates();
postData(lat, lon);
return true;
}
protected void onPreExecute() {
// show progress dialog
}
protected void onPostExecute(Long result) {
// hide progress dialog
}
}
【问题讨论】:
-
你能给我们看看你的logcat吗?
-
-
我认为这不是问题所在。即使我不使用 asyncTask 而只是调用一些执行请求的方法,它也会崩溃。
-
我复制了 logcat,但效果不如你所见。有人可以为我编辑吗?谢谢。
-
你能发布你的 PostAsyncTask
标签: php android android-asynctask push-notification android-service