0

My application activity is facing a scenario when user press Home button on android phone.

I have used OnPause() method . this i called when user press Home key. and Normal cicumstances when user launch the app again, it calls the onResume() method of the activity.

But sometimes, when user re-launch the application, it opens the Launcher Activity(instead of calling the current activity.)

So I am confused. in my phone it always calls the current activity. But sometime on another phone, i see that it calls the launcher activity and application starts again.

How to solve this issue? Am i doing something wrong?

Sunil
  • 521
  • 1
  • 7
  • 24
  • What are you doing in your onPause() and onResume() methods? Android manages memory differently on different phones depending on available memory. Quite possibly the app is killed after it is no longer active, even if you used the home key to exit. Read about activity lifecycle to find out more. – RufusInZen Nov 06 '14 at 02:11
  • You should save the last position in onPause/onDestroy. So, when user come back, you restore the last position – tana Nov 06 '14 at 03:00

2 Answers2

0

Try android:launchMode="singleTop".

As the doc says:

If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.

StoneBird
  • 1,900
  • 13
  • 12
0

Press the home button means minimize the application.It's not clear stack,then app will goto onPause() and onStop() state.When user launch the application it's executes onResume() method because app instance is already created.

Borra Suneel
  • 196
  • 1
  • 2
  • 6