This is my sistuation
A1 = Splash Screen Activity
A2 = Main Activity
A3 = Extra Activity
S1 = GPS Service
I start with A1 that creates intent to launch A2 and then A1 finish. Inside A2 I create and bind S1 (Inside S1 I make a Notification)
CharSequence text = getText(R.string.local_service_started);
Notification notification = new Notification(R.drawable.notify_icon, text, System.currentTimeMillis());
Intent i = new Intent();
i.setClassName("xxx.yyy.zzz.kkk", "xxx.yyy.zzz.kkk.A2");
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent);
mNM.notify(NOTIFICATION, notification);
Now I have my icon in the notification bar If I press HOME button inside my A2 activity and open another application and then I press my notification icon all is working correctly and I gate back my A2 activity(A2 is the top most activity), but if inside A2 I launch A3 and go back HOME and press the notification I have the problems, A2 is created as a new instance(A2 now isn't top most)! Is possible to have the effect like long press HOME and focus the last open activity inside my application? I don't want to open a specific activity, but bring to front my paused activity without a new instance of the activity.
I have solved, this open my application preserving the actual state and get the opened activity back form background to foregraund. Do the same think of app selecting from RECENTS !
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
i.setComponent(new ComponentName(getApplicationContext().getPackageName(), MyAppClass.class.getName()));
MyAppClass is the 1st Activity your APK is launching.
Best regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With