I got an app with tabs and a notification bar entry, when I send it to background (click on home button) and try to re-open the application via click on the notification ba
use two flags in intent
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Are you implementing the onSaveInstanceState methods as recommended in the lifecycle documentation?
Its possible that when you pause an application and go back to it immediately, that the application is still hanging out in memory in the background. However, you can't depend on this, so you should save state like the currently open tab everytime you go into the background, and restore it when you get reactivated.
Put these two lines. This will resume currently paused activity:
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
I have faced the same issue and searched vehemently for an answer but here s the trick: Instead of trying to restart the app with the saved state using your notification intent, open a blank activity using the notification intent and in the onCreate() method of the activity, simply finish() it. This will take you back to the last viewed activity on the app.
Intent intent = new Intent(Application.getContext(), ActivityHome.class);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Application.getContext().startActivity(intent);
public static boolean isApplicationRunningBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(am.getRunningAppProcesses().size());
for (RunningTaskInfo runningTaskInfo : tasks) {
if (runningTaskInfo.topActivity.getPackageName().equals(context.getPackageName())) {
MyLog.i("UTIL", "packageName:" + runningTaskInfo.topActivity.getPackageName());
MyLog.i("UTIL", "className" + runningTaskInfo.topActivity.getClassName());
return true;
}
}
return false;
}
Intent notificationIntent;
if (Util.isApplicationRunningBackground(context)) {
notificationIntent = new Intent(context, MainView.class);
} else {
notificationIntent = new Intent(context, Splash.class);
}