android displaying multiple activity in saved state when notification click -


i have notification on app. works in foreground well. when i`m in other activity , press home button after click notification. opens given activity, need display previous activity in saved state.

        notification note = new notification(r.drawable.service_state_0,             getresources().gettext(r.string.servicestarted),             system.currenttimemillis());     intent = new intent(this, startingactivity_.class);      i.setflags(intent.flag_activity_clear_top             | intent.flag_activity_single_top);     pendingintent pi = pendingintent.getactivity(this, 0, i, 0);     note.setlatesteventinfo(this,             getresources().gettext(r.string.app_name), getservicestatedescription(customservice.this), pi);     note.flags |= notification.flag_no_clear;     note.flags |= notification.flag_ongoing_event;      startforeground(contextconstants.launcher_service_note_id, note); 

it shows startingactivity, question how call resuming activity when notification clicked. if activity has not been destroyed , can call instance back(resume it) , therefore not needing load again , won't need add activity stack. possible?

i find solution open activity in notification:

notificationmanager nm = (notificationmanager) getsystemservice(context.notification_service); notification notification = new notification(); notification.flag = notification.flag_ongoing_event | notification.flag_no_clear;  intent nintent = new intent(); nintent = getpreviousintent();  pendingintent pi = pendingintent.getactivity(this, 0, nintent, 0); notification.setlatesteventinfo(getcontext(), "some title", "some text", pi); nm.notify(0,notification); 

private intent getpreviousintent(intent newintent) {     final activitymanager = (activitymanager) getsystemservice(context.activity_service);     final list<activitymanager.recenttaskinfo> recenttaskinfos = am.getrecenttasks(1024,0);     string mypkgnm = getpackagename();      if (!recenttaskinfos.isempty()) {         activitymanager.recenttaskinfo recenttaskinfo;         (int = 0; < recenttaskinfos.size(); i++) {             recenttaskinfo = recenttaskinfos.get(i);             if (recenttaskinfo.baseintent.getcomponent().getpackagename().equals(mypkgnm)) {                 newintent = recenttaskinfo.baseintent;                 newintent.setflags(intent.flag_activity_new_task);             }         }     }     return newintent; } 

you have add <uses-permission android:name="android.permission.get_tasks" />


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -