Want to go back to the last event after clicking the Launcher icon for my app

Suppose I have activity A which starts activity B and kills itself. Now I press the Home button (or leave the app in some other way) (by calling onPause-> onStop for activity B) and I press the app icon in the launcher again. What happens is that Activity A is fired again (of course, because I indicated that the intent filter in the XML manifest). Is there an easy way to just go back to activity B without starting A again? Basically I want to get onStart-> onResume in Activity B when I open the app again.

My filter intent looks like this:

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



source to share

2 answers

Maybe I have a workaround.
How do I use a transparent activity as a trigger?

When B pauses or stops, remember it (in file, db, etc.). In the startup activity, something like a welcome screen but with a transparent look, read the entry and start the recorded activity.

Another solution, but not sure if it works.

Write a broadcast receiver with a trigger filter and then trigger the recorded activity.



One strategy might be to keep the SharedPreference, flag when you want to go straight to B. This Android doc talks about using SharedPreferences, with some code examples.

Basically, when you want to go straight back to B, you create a general preference to indicate this. Then, when A restarts (say because it was killed by the OS, as discussed in the comments to the question), instead of immediately setting the appropriate view, etc., you check the flag first. If the flag is on, you start B. There is some confusion here, but I think it could be handled in a very clean way.



All Articles