android - How to handle GCM Notifications when different GCM notifications receive -


i using gcm notification in app.i parse data in "onmessagereceived" method unique "url" corresponding gcm message.when receive single notification every thing fine,but when receive multiple notifications problem occurs when tap notification last received notification url loads.

public void onmessagereceived(string from, bundle data) {          string message = data.getstring("message");         string country = data.getstring("country");         string url = data.getstring("url");         string description = data.getstring("description");         string id = data.getstring("id"); } 

i url gcm notification

intent intent = new intent(this, detailview.class).putextra("url", url);  taskstackbuilder stackbuilder = taskstackbuilder.create(this); stackbuilder.addparentstack(mainscreen.class); stackbuilder.addnextintent(intent);  pendingintent pendingintent= stackbuilder.getpendingintent( 0, pendingintent.flag_one_shot ); remoteviews contentview = new remoteviews(getpackagename(), r.layout.custom_notification_layout); contentview.setimageviewresource(r.id.image, r.drawable.ic_stat_ic_notification); contentview.settextviewtext(r.id.title, message); uri defaultsounduri = ringtonemanager.getdefaulturi(ringtonemanager.type_notification); notificationcompat.builder notificationbuilder = new notificationcompat.builder(this)         .setsmallicon(r.drawable.ic_stat_ic_notification)         .setautocancel(true)         .setcontent(contentview)         .setsound(defaultsounduri)         .setcontentintent(pendingintent); notificationmanager notificationmanager =         (notificationmanager) getsystemservice(context.notification_service); notificationmanager.notify(integer.parseint(id)             /*id of notification */         , notificationbuilder.build()); 

so when tap notification able launch last url how can solve problem?

use

pendingintent.flag_update_current  

when creating pendingintent.

also before passing intent pendingintent set action different everytime. e.g.:-

intent.setaction(long.tostring(system.currenttimemillis())); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -