3

In my application after navigating from the Splash screen to another activity, I minimize it by pressing the Home button and then open my application again and instead of opening from the activity that I was last in, it starts from the Splash screen again.

Can you please tell me why this is happening?

rekire
  • 47,260
  • 30
  • 167
  • 264
Ingrid Cooper
  • 1,191
  • 3
  • 16
  • 27

2 Answers2

3

In your scenario,after installing the application,if you press the OPEN button the your activity will be brought to front not created. Please paste the following code in your first activity and test it. It works for me.

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
    // Here activity is brought to front, not created,
    // so finishing this will get you to the last viewed activity
    finish();
    return;
  }
}
laalto
  • 150,114
  • 66
  • 286
  • 303
  • @ingrid Cooper Please accept the answer if my solution worked for u – Ravi Swaminathan Sep 21 '13 at 11:31
  • This can't possibly be correct. If the application was just installed, how can it possibly "bring to the front" an `Activity` that hasn't been created? Also, you've got this code in `onCreate()`, so obviously Android is creating a new instance of this `Activity`. Not only that, but `Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT` is only set in one condition, and that is when `onNewIntent()` is called on an Activity that has already been created with `launchMode="singleTask"`. I'm afraid this answer is just likely to confuse people. – David Wasser Jan 14 '14 at 18:59
0

Properly you application has been exited. If you app need much memory it is very common that the app will be terminated by the system.

rekire
  • 47,260
  • 30
  • 167
  • 264
  • This is wrong. Even if Android killed the process due to resource requirements, it would still remember which Activity was on the top of the stack and when the user returned to the application it would recreate the process and show the Activity that was on the top of the stack when the process was killed. – David Wasser Jan 14 '14 at 19:01
  • Hi David, I am having the same problem . How do I fix it ? – May13ank Jun 17 '15 at 15:01
  • The same is with me. Any solution ? – Misha Akopov Nov 30 '16 at 09:36