2

the flow is like below.

  • MainActivity -> Second Activity
  • Press home key then device main screen shown.
  • Enter to app box and click the application icon.

I expect the second activity should be launched but main activity launched.

is there any way that I control it -?!

J.ty
  • 337
  • 1
  • 3
  • 18

4 Answers4

0

The default Android behaviour when you press the home button is that the current activity is pushed onto the stack, unless you called finish() in your activity. Whenever you open your application it will launch the activity that's on top of your stack.

I'ts based on your system memory. If you don't have enough memory to keep your activity backgrounded then Android will kill your activity and its state to recoup some memory. I'm thinking that perhaps your phone (or emulated device) is running short of memory.

eriegz
  • 335
  • 3
  • 10
Mr.Popular
  • 845
  • 1
  • 8
  • 15
0

Check if you are using for that activity, any android:noHistory="true" within your App's manifest. Try removing it.

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
Gouz
  • 336
  • 1
  • 6
  • 19
-1

You filtered your main activity by

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

so it should get launched when you click on the icon in your launcher. I think you should handle your pages with fragments to have the behavior you want.

hadilq
  • 1,023
  • 11
  • 25
  • There is no need for fragments to get this standard, default Android behaviour. Using fragments won't solve this problem. – David Wasser Dec 05 '16 at 14:30
-1
boolean isSentToBackground = false;

public void onResume(){
 if(isSentToBackground) {
  finish();
 }
}

public void onPause(){
 isSentToBackground = true;
}
  • Can you provide more context? I have little experience with Android apps, but where does this restore the previous activity? – Nico Haase Apr 10 '18 at 20:11