我的需求是當推送通知進入我的設備時,我需要調用Asynctask。該應用可以在後臺運行。我不應該點擊通知,而是在需要時調用Asynctask。那可能嗎?當出現推送通知時調用Asynctask
1
A
回答
2
在您的GCMIntentService中,只需重寫onMessage(..)方法,此方法在推送通知正在設備中調用時調用。
@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();
}
+0
感謝您儘快回覆.. – Mathew
1
相關問題
- 1. 推送通知推送出現兩次?
- 2. 推送通知不出現
- 3. 「暖」推出推送通知
- 4. 當使用Parse.com推送通知時,不會調用onnewIntent方法
- 5. 推送通知徽章沒有出現?
- 6. 推送通知的TabBar不會出現
- 7. 蘋果推送通知出現SSLHandshakeException
- 8. 從PHP發送推送通知時出現主鍵錯誤
- 9. Android:當我點擊推送通知時如何調用功能
- 10. 當推送通知進入時被調用的方法序列
- 11. 推送通知當地時區
- 12. 當應用運行時顯示從推送通知彈出
- 13. 使用示例代碼推送通知時出現404錯誤
- 14. 每當我打開我的應用程序時,推送通知不斷出現
- 15. 當靜默推送通知/推送通知命中設備時調用的委託方法
- 16. 火力地堡推送通知 - 如何出現在通知
- 17. Android - 未出現在通知列表中的GCM推送通知
- 18. 每當通過推送通知打開應用程序時調用rest-api
- 19. 使用解析實現推送通知
- 20. 推送推送通知
- 21. Openfire發送當用戶離線時推送通知
- 22. Auth0 MFA Guardian app.I當我按下推送通知中的「allow_button」時出現錯誤
- 23. 嘗試點擊推送通知時出現錯誤Android
- 24. 在linux上部署後推送通知時出現錯誤
- 25. 接收蘋果推送通知時出現問題
- 26. 推送通知出現時暫停遊戲
- 27. 實時推送通知golang
- 28. PHP實時通知(推送?)
- 29. 時區 - 推送通知
- 30. 使用Symfony2調度推送通知
是的這是可能的你想使用GCM! –
是的,我打算使用GSM – Mathew
我可以知道你在Asynctask中需要做什麼 –