android - Restarting (and showing) a stopped activity -
i have background service can create persistent notifications. when user clicks on notification starts activity. user may press home button causing activity stopped.
if user clicks on notification again want restart (and show) same activity (if android hasn't destroyed - appreciate can), gui state user left it.
how can achieve this?
manifest entry activity
<activity android:name=".mrwidget.mrwidget" android:theme="@android:style/theme.notitlebar" android:launchmode="singletask"> <intent-filter><action android:name="android.intent.action.main"> </action> <category android:name="android.intent.category.launcher"></category> </intent-filter> </activity> what i'm after same behaviour if activity selected 'recent apps list' when hold down home button.
to elaborate - when click on notification first time create activity using:
intent.setflags(intent.flag_activity_new_task); mservice.startactivity(i); if pressed home button switch away activity , held home button down bring "recent apps list" , selected activity there works expected - activity shown in state left, good.
i want same behaviour when select same notification subsequent time, i.e. displays created activity. attempted using:
intent.setflags(intent.flag_activity_reorder_to_front); activity.startactivity(intent); where 'activity' reference activity created first time user selected notification, doing doesn't cause activity displayed.
to have same behaviour "bringing app foreground", need create intent contains root activity , set intent.flag_activity_new_task. root activity activity has action=main , category=launcher in manifest. this:
intent intent = new intent(this, myrootactivity.class); intent.addflags(intent.flag_activity_new_task);
Comments
Post a Comment