English 中文(简体)
当应用程序在安卓系统中从后台到前台时,如何重新启动应用程序?
原标题:How to relaunch application when app went to background to foreground in android?

在我的应用程序中,我遇到了一个问题,当应用程序进入后台(按下主页按钮)时,我应该在应用程序进入前台时重新启动它,而不是获得以前的状态。

有人能帮我解决这个问题吗。

编辑:

我清楚地解释了我的问题,我有四个活动A1、A2、A3、A4。

A1 - ListActivity - loading events from server. A2 - SearchActivity A3- EventDetail page

看看我目前是否在A3,然后我转到后台,当我到达forround时,我应该显示A1(同样,我有来自服务器的更新数据)。最后我想重新启动应用程序。

Regards, Srinivas

最佳回答

尝试在homeActivity的清单文件中将“android:clearTaskOnLaunch”属性设置为true。这样,当您按下home按钮时,一旦应用程序重新启动,它将显示您的homeActivity,而不是上次启动的活动。

问题回答

我在自己制作的应用程序中也做了同样的事情。基本上,我只是使用了onResume函数,当应用程序从后台进入前台时会调用该函数来重新启动活动。只要添加它并重新启动活动,你的应用程序就会在每次加载时重新启动(我相信这正是你想要的)。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签