简体   繁体   English

当应用程序在 android 中从后台转到前台时如何重新启动应用程序?

[英]How to relaunch application when app went to background to foreground in android?

In my application, i had wierd problem that when app goes background (press home button), then i should restart my app when it comes to foreground, Instead of getting previous state.在我的应用程序中,我遇到了一个奇怪的问题,即当应用程序进入后台(按主页按钮)时,我应该在前台重新启动我的应用程序,而不是获取以前的 state。

Can any one help me to sort out this.任何人都可以帮我解决这个问题。

EDIT:编辑:

i explain my problem clearly,I am having four Activities A1,A2,A3,A4.我清楚地解释了我的问题,我有四个活动 A1、A2、A3、A4。

A1 - ListActivity - loading events from server. A1 - ListActivity - 从服务器加载事件。 A2 - SearchActivity A3- EventDetail page A2 - SearchActivity A3- 事件详情页面

See if i was currently in A3 then i went to background, when i come to forground i should display A1 (Again i have update data from server).看看我当前是否在 A3 中,然后我进入后台,当我来到前台时,我应该显示 A1(我再次从服务器获得更新数据)。 Finally i want restart app.最后我想重新启动应用程序。

Regards, Srinivas问候, 斯里尼瓦斯

Try to set in the manifest file for your homeActivity the "android:clearTaskOnLaunch" property to true.尝试在您的 homeActivity 清单文件中将“android:clearTaskOnLaunch”属性设置为 true。 In this way when you press the home button, once the application is restarted it will display your homeActivity instead of the last started activity.这样,当您按下主页按钮时,一旦应用程序重新启动,它将显示您的 homeActivity 而不是上次启动的活动。

I do the same thing in an app I made.我在我制作的应用程序中做同样的事情。 Basically I just used the onResume function that is called when the app comes into the foreground from the background to restart the activity.基本上我只是使用了应用程序从后台进入前台时调用的 onResume function 来重新启动活动。 Just add that and restart the activity and your app will restart each time you load it (which I believe is what you want).只需添加它并重新启动活动,您的应用程序将在每次加载时重新启动(我相信这是您想要的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当Android应用程序在后台运行时捕获 - Catch when Android application went on background 如何检测 android 应用程序何时在后台和前台处理一些代码 - how to detect when android app in background and foreground to handle some code 如何检测Android应用程序何时进入后台并返回前台 - How to detect when an Android app goes to the background and come back to the foreground 如何检查Android应用程序是在后台运行还是在前台运行? - How to check if an Android application is running in the background or in foreground? 如何知道我的应用程序是在前台还是后台,android? - How to know if my application is in foreground or background, android? 从后台恢复时重新启动应用程序 - Relaunch app when resuming from background 如何将Android应用程序从前台传递到后台 - How to pass Android app from foreground to background Android:当我的应用程序通过单击主页键一段时间后进入后台时,然后重新启动时,该应用程序崩溃了 - Android:When my App go to background by click home key for a while, then when I relaunch,the app is crashed 单击应用程序图标时,应用程序重新启动 - App relaunch when clicking on application icon Android (Kotlin) - 使用应用程序观察应用程序背景/前景 - Android (Kotlin) - Use Application to observe app background/foreground
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM