简介
我不确定这是否是Android中的错误。但是,我的活动已从Back Stack中删除,并且在将应用程序放在前面后,它的onCreate
方法永远不会被调用。
方案
Back Stack中有3项活动:
当我锁定显示器(将其关闭)时,我可以从锁定的屏幕运行相机。当我从锁定屏幕运行它时,Camera应用程序无法启动(因为我们的MDM应用程序中缺少权限,Camera失败的行为是正常的)。相机失败后,会显示“相机已停止”对话框。这也行。问题是,在我确认“Camera stopped”对话框后,Activity03将从Back Stack中删除。 BackStack看起来像这样:
注意:从锁定屏幕运行相机应用程序的方案只是重现问题的快捷方式。有时在解锁显示后立即销毁活动。不幸的是,这很难再现,每天只发生一次/两次。所以我使用相机场景作为捷径。
如果我再次锁定屏幕并从锁定屏幕运行相机应用程序,该应用程序将再次失败,现在将删除Activity02。然后Back Stack只包含Activity01:
解决方案提示/讨论
onCreate
方法。或者我错过了什么?onCreate
。android:persistent
属性可以添加到AndroidManifest的application
元素中。但是,如果应用程序未在“系统空间”中运行,则会忽略此属性。这不是我的情况,我的设备没有root,我的应用程序必须在“用户空间”运行。修改
日志输出:
Screen locked:
03-05 23:03:41.430 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onPause()
03-05 23:03:41.440 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onStop()
Screen unlocked:
03-05 23:03:54.514 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onRestart()
03-05 23:03:54.514 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onStart()
03-05 23:03:54.514 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onResume()
03-05 23:03:54.554 27370-27370/com.myapp I/ActivityManagerProxy: Timeline: Activity_idle id: android.os.BinderProxy@425a4370 time:821210127
03-05 23:03:54.844 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onPause()
03-05 23:03:56.205 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onStop()
03-05 23:04:00.350 27370-27370/com.myapp I/*atformAbstractActivity: com.myapp.ui.Activity03.onDestroy()
修改2
添加了ActivityManager.MemoryInfo的输出:
第一次调用Activity03.onStart()
时的内存状态:
availMem = 315891712
foregroundAppThreshold = 50331648
hiddenAppThreshold = 100663296
visibleAppThreshold = 62914560
secondaryServerThreshold = 100663296
threshold = 100663296
totalMem = 872062976
lowMemory = false
屏幕解锁后调用Activity03.onStart()
时的内存状态:
availMem = 316497920
foregroundAppThreshold = 50331648
hiddenAppThreshold = 100663296
visibleAppThreshold = 62914560
secondaryServerThreshold = 100663296
threshold = 100663296
totalMem = 872062976
lowMemory = false
屏幕解锁后调用Activity03.onDestroy()
时的内存状态:
availMem = 317919232
foregroundAppThreshold = 50331648
hiddenAppThreshold = 100663296
visibleAppThreshold = 62914560
secondaryServerThreshold = 100663296
threshold = 100663296
totalMem = 872062976
lowMemory = false
编辑3
onDestroy()
方法调用的堆栈跟踪:
"<1> main@830034095704" prio=5 runnable
java.lang.Thread.State: RUNNABLE
at sk.plaut.mobileplatform.client.ui.MainActivity.onDestroy(MainActivity.java:57)
at android.app.Activity.performDestroy(Activity.java:5428)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3473)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3504)
at android.app.ActivityThread.access$1400(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1252)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5034)
at java.lang.reflect.Method.invokeNative(Method.java:-1)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(NativeStart.java:-1)