问题,当应用程序回来前景 [英] Issue when app coming back to foreground

查看:124
本文介绍了问题,当应用程序回来前景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序崩溃,当谈到回到前台后的一段时间玩其他的应用程序,我无法找到如何解决它。

my app crashes when it comes back to foreground after some time playing with others applications and I can't find out how to fix it.

我的应用程序都有一个启动画面的活动,其中加载一些数据网络服务,并把它放在一个类扩展应用程序中声明全局静态变量,如的这太问题。一旦加载的所有数据,本次活动将启动一个家庭活动的一些菜单中的应用程序导航。在全局变量被用在大多数活动。

My app has a splash screen activity where it loads some data from web services and put it in global static variables declared in a class extending Application, as explained in this SO question. Once all data are loaded, this activity launches a Home activity with some menu to navigate in the app. The global vars are used in most activities.

在某些时候,同时与其他的应用程序打,看来我的应用程序被杀死了,因为我可以看到在logcat中:

At some point, while playing with other apps, it seems that my app is killed, because I can see this in the logcat:

I/ActivityManager( 2465): Process com.mysite.myapp (pid 23538) has died.
I/WindowManager( 2465): WIN DEATH: Window{4852a678 com.mysite.myapp/com.mysite.myapp.Home paused=false}
I/WindowManager( 2465): WIN DEATH: Window{485b63a8 com.mysite.myapp/com.mysite.myapp.Home paused=false}
I/WindowManager( 2465): WIN DEATH: Window{4826fbf8 com.mysite.myapp/com.mysite.myapp.ItemList paused=false}
I/WindowManager( 2465): WIN DEATH: Window{48286f90 com.mysite.myapp/com.mysite.myapp.ItemDetail paused=false}
W/GpsLocationProvider( 2465): Unneeded remove listener for uid 1000
D/GpsLocationProvider( 2465): stopNavigating
D/gps_BRCM( 2465): [status check] on_stop() : GPS_STATUS_SESSION_END
D/gps_BRCM( 2465): gps_engine_status_update 2
D/GpsLocationProvider( 2465): send an intent to notify that the GPS has been enabled or disabled
D/gps_BRCM( 2465): gps_stop: called
V/GpsLocationProvider( 2465): hybridGpsSensorDeregister : No registered sensorManager
D/GpsLocationProvider( 2465): hybridGpsSensorDeregister

和调试器被分离。

现在,当我再次打开我的应用程序,最新的活动开始,如果不使用全局变量(在这种情况下,当我浏览到该做的活动崩溃),或立即崩溃,如果它。

Now, when I open my app again, the latest activity is started if it does not use global vars (in that case it crashes as soon as I navigate to an activity which does), or crashes immediately if it does.

如果我的应用程序被打死,这似乎是这种情况,因为即使我的位置服务被停止,因为在logcat中看到,为什么它打开,而不是从初始屏幕再次推出最新的活动呢?

If my app was killed, which seems to be the case because even my location service is stopped, as seen in the logcat, why does it open the latest activity instead of launching again from the splash screen?

推荐答案

一个肮脏的解决方法的问题是检查全局变量填充在的 onResume方法,你的活动。如果这些变量没有填充启动闪​​屏活性与 CLEAR_TOP <一个Intent / A>标志设置。这应当引起所有的活动,从活动的堆栈被删除,闪屏会加载,并能加载所有您的应用程序所需的所有数据。

A dirty workaround to your problem is to check if the global variables are filled in the onResume method of your activities. If the variables are not filled start the splashscreen activity with an Intent with the CLEAR_TOP flag set. This should cause all your activities to be removed from the activity stack and your splash screen will load and is able to reload all the data needed for your app to work.

这是一个肮脏的解决方法,以帮助设计糟糕的应用程序工作。 如果你希望你的应用程序是更好的为您和用户去提供的解决方案inazaruk。他是正确的关于应用程序的基本设置。

This is a dirty workaround to help a badly designed application to work. If you want your app to be nicer to you and the user go with the solution inazaruk provided. He is correct about the basic setup of an application.

这篇关于问题,当应用程序回来前景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆