问题
After tap on app icon,launcher create a new instance of root activity & onCreate() of root activity is called when root activity already present in background i.e onPause(). It creating a new instance of root activity again & again instead of onResume() root activity.
I know This is due to the intents being used to start the app being different. Eclipse starts an app using an intent with no action and no category. The Launcher starts an app using an intent with android.intent.action.MAIN action and android.intent.category.LAUNCHER category. The installer starts an app with the android.intent.action.MAIN action and no category.
After long searching I have found the following code It is working.but I think it is workaround.Is there any other solution except following code.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
// Activity was brought to front and not created,
// Thus finishing this will get us to the last viewed activity
finish();
return;
}
// Regular activity creation code...
}
来源:https://stackoverflow.com/questions/28043865/after-tap-on-app-icon-launcher-create-a-new-instance-of-root-activity-again-ag