安卓避免OnResumeOnResume

2023-09-04 05:30:47 作者:劳资、何曾输过

我有3个Acivity基础的应用程序,它是这样的工作流程 MainActivity 的ListView 的DetailView 。当onResume事件触发,需要调用MainActivity。无需另外两个活性

I have 3 Acivity based application, It's work flow like this MainActivity ListView and DetailView. when onResume event trigger , need to call MainActivity. without going to other two activity.

有什么办法叫 MainActivity 时,onResume事件触发?

Is there any way to call MainActivity when onResume event trigger?

感谢您

推荐答案

您可以设置安卓clearTaskOnLaunch =真正的属性您MainActivity在AndroidManifest.xml文件。请参见这里找到原因和更多的细节。我觉得这是最便捷的方式,以满足您的需求。

You can set the android:clearTaskOnLaunch="true" attribute for you MainActivity in the AndroidManifest.xml file. See here to find why and more details. I think this is the most convenient way to meet your demand.

编辑: 我只是测试,发现当您退出应用程序,并从应用程序的抽屉启动的应用程序,这仅适用(不长preSS回家,然后选择应用程序)。

I just tested and found this only works when you exit the app and launch the app from the app drawer(NOT long press on HOME and select the app).

如果你想永远把根系活力的前面,无论你什么时候重新启动应用程序,或从最近的画面。你可以声明机器人:launchMode =singleTask的根系活力,在这里,MainActivity

If you want to always bring the root activity to the front, no matter when you re-launch the app or from the recent screen. You can declare "android:launchMode="singleTask" for the root activity, here, the MainActivity.