Want to get back to last Activity after pressing Launcher Icon for my app

旧城冷巷雨未停 提交于 2019-12-05 19:25:12

Maybe I have a workaround solution.
How about using a transparent activity as the launcher?

When B pause or stop, remember it (in file, db etc.) In the launcher activity, something like a welcome screen but with a transparent view, read the record, and start the recorded activity.

Another solution, but not sure if it works.

Write a broadcast receiver with a launcher filter, and then launch the recorded activity.

One strategy here could be to save a SharedPreference, flagging when you want to go straight to B. This Android doc talks about using SharedPreferences, with some code examples.

Essentially, when you want to return straight to B, you create a shared preference indicating this. Then, when A restarts (say, because it was killed by the OS as discussed in the comments on the question), rather than immediately setting the associated view, etc, you first check the flag. If the flag is on, you start B. There is some messiness here, but it could potentially be handled in a very clean way, I think.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!