本文介绍了呼叫AsyncTask的推送通知时出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的要求是,当一个推送通知进来我的设备,我需要调用一个AsyncTask的。应用程序可以在后台运行。我不应该单击该通知,而不是当谈到我需要调用的AsyncTask。这可能吗?
My requirement is when a push notification comes in my device, I need to call an Asynctask. The app can be running in background. I shouldn't click the notification, instead when it comes I need to call Asynctask. Is that possible?
推荐答案
在您的GCMIntentService只是覆盖的onMessage(..)方法时,推送通知在正在添加的设备调用此方法。
In your GCMIntentService just override onMessage(..) method this method called when push notification is comming in device.
@Override
protected void onMessage(Context context, Intent intent) {
mContext = context;
final String message = intent.getStringExtra("message");
Log.e(TAG, "GCM Received message : "+message);
AsyncTask<Void, Void, Void> DatabaseOperationTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
// do your Database Operation here
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
};
DatabaseOperationTask.execute();
}
这篇关于呼叫AsyncTask的推送通知时出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!