Android - Update status bar notification -


i have created android application, polls server once in 2 minutes making use of alarm service. after alarm triggers service intent, poll server new data. if new data available, status bar notification generated using notificationmanager class.

i have few queries here:

  1. at first notification generated indicating new data update arrived server. after 2 minutes, again new data available. how know whether user clicked old notification or not? knowing decide whether put "new message arrived" or "2 new messages arrived"

  2. how can update existing notification service intent itself?

  3. how can extras , append in listview of activity? each time click notification, new listview created in activity , message appended.

pollingserver.class:

            notificationmanagercompat.from(this).cancelall();              intent notificationintent= new intent(this, messages.class);             notificationintent.putextra("msg",toasttext);              taskstackbuilder stackbuilder=taskstackbuilder.create(this);             stackbuilder.addparentstack(messages.class);             stackbuilder.addnextintent(notificationintent);              pendingintent contentintent = pendingintent.getactivity(context, 0, notificationintent, pendingintent.flag_update_current);             notificationcompat.builder mbuilder =                     new notificationcompat.builder(context)                             .setsmallicon(r.drawable.clove)                             .setcontenttitle("my notification")                             .setcontenttext(toasttext)                             .setcontentintent(contentintent)                             .setdefaults(notification.default_sound)                             .setautocancel(true);              notificationmanager mnotificationmanager =                     (notificationmanager) context.getsystemservice(context.notification_service);             mnotificationmanager.notify(1, mbuilder.build()); 

messages.class:

            private listview mainlistview;              @override             protected void oncreate(bundle savedinstancestate) {              super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_messages);             bundle extras = getintent().getextras();             final string msg = extras.getstring("msg");              // find listview resource             mainlistview = (listview) findviewbyid(r.id.listview);             arrayadapter<string> arrayadapter = new arrayadapter<string>(getapplicationcontext(),android.r.layout.simple_list_item_1);             mainlistview.setadapter(arrayadapter);             arrayadapter.add(msg);           } 


Comments