php - Executing some code when a push notification is recived on onMessage() -
this code, , have execute http request in asynctask when push notification received. understood if need when push notification arrives, have within onmessage() method. app crashes when receives notification , not need do: code:
@override protected void onmessage(context context, intent intent) { log.i(tag, "received message"); string message = intent.getextras().getstring("price"); //sends info server new postasynctask().execute(); displaymessage(context, message); // notifies user generatenotification(context, message); }
thank much! (in case need whole class it. can tell postasynctask executes httprequest code.)
logcat:
asynctask: (it calls function executes http request)
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 } }
i guess, should not use asynctask onmessage method of push notification. should call service task of making http connection. remember use separate thread if using service class runs on ui thread only. hope helps out.
Comments
Post a Comment