0

Say someone is using my app, and they get to a critical state, ex they are entering some data. Say at that same time the phone rings so they answer the phone, forcing my app into the background. After the phone call ends, if they click on the icon of my app, I want it to bring them back into the activity they left. How do I do that?

Edit

One thing I forgot to clarify (apologies) is that the activity the user left is not the main activity. I need to re-open the app in an activity that is normally not the main entry point.

user3093402
  • 1,419
  • 4
  • 20
  • 28
  • i think savedinstancestate in onpause() will help you here.otherwise save current state in sharedpreference also help you. – Ranjit Feb 04 '14 at 18:29

1 Answers1

-1

To keep the system from launching another instance of your activity, you should add launchMode="singleTop" to your activity.

AndroidManifest.xml

<activity
    ....
    ....
    android:launchMode="singleTop" />

What this will do:

When the user tries to launch your app (after the phone call, for instance), system will check if your launcher activity is already running && at the top of the stack. If it is, a new instance will not be created, and your activity will be resumed. Top of the stack condition is important. Depending on your requirements, you may want to opt for singleTask launch mode.

More info here: Link

user3264740
  • 231
  • 1
  • 2
  • 13