Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 活动在强制关闭时重新启动_Android_Android Activity_Crash_Kill_Activity Stack - Fatal编程技术网

Android 活动在强制关闭时重新启动

Android 活动在强制关闭时重新启动,android,android-activity,crash,kill,activity-stack,Android,Android Activity,Crash,Kill,Activity Stack,我有一个具有单个根活动的应用程序。我最近注意到,任何靠近我的活动的力都会导致它重新启动,我不知道为什么会发生这种情况。如果我强制执行未捕获的异常或使用“长时间后按以强制关闭”选项,它们都会导致相同的结果 我唯一的猜测可能是与保留对活动某些部分的引用有关的某种形式的怪癖,只是我在应用程序级别没有任何外部的WeakReference条目 相关logcat条目: 05-25 08:25:49.137: INFO/ActivityManager(18449): Displayed uk.co.rando

我有一个具有单个根活动的应用程序。我最近注意到,任何靠近我的活动的力都会导致它重新启动,我不知道为什么会发生这种情况。如果我强制执行未捕获的异常或使用“长时间后按以强制关闭”选项,它们都会导致相同的结果

我唯一的猜测可能是与保留对活动某些部分的引用有关的某种形式的怪癖,只是我在应用程序级别没有任何外部的WeakReference条目

相关logcat条目:

05-25 08:25:49.137: INFO/ActivityManager(18449): Displayed uk.co.randomicon.rstb/.TreeBuilderActivity: +8s82ms
05-25 08:25:54.222: DEBUG/dalvikvm(18546): GC_EXPLICIT freed 12K, 57% free 3640K/8327K, external 8323K/10136K, paused 72ms
05-25 08:25:55.373: WARN/InputManagerService(18449): Got RemoteException sending setActive(false) notification to pid 19122 uid 10069
05-25 08:25:59.217: DEBUG/dalvikvm(18646): GC_EXPLICIT freed 128K, 48% free 2980K/5703K, external 0K/0K, paused 67ms
05-25 08:26:00.238: DEBUG/dalvikvm(18991): GC_CONCURRENT freed 343K, 51% free 2794K/5639K, external 303K/532K, paused 3ms+3ms
05-25 08:26:02.950: INFO/Process(18449): Sending signal. PID: 19554 SIG: 9
05-25 08:26:02.980: INFO/ActivityManager(18449): Process uk.co.randomicon.rstb (pid 19554) has died.
05-25 08:26:02.990: ERROR/InputDispatcher(18449): channel '40a16ec8 uk.co.randomicon.rstb/uk.co.randomicon.rstb.TreeBuilderActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
05-25 08:26:02.990: ERROR/InputDispatcher(18449): channel '40a16ec8 uk.co.randomicon.rstb/uk.co.randomicon.rstb.TreeBuilderActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
05-25 08:26:02.990: INFO/WindowManager(18449): WINDOW DIED Window{40a16ec8 uk.co.randomicon.rstb/uk.co.randomicon.rstb.TreeBuilderActivity paused=false}
05-25 08:26:03.010: WARN/WindowManager(18449): Failed looking up window
05-25 08:26:03.010: WARN/WindowManager(18449): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@40c774e0 does not exist
05-25 08:26:03.010: WARN/WindowManager(18449):     at com.android.server.WindowManagerService.windowForClientLocked(WindowManagerService.java:8177)
05-25 08:26:03.010: WARN/WindowManager(18449):     at com.android.server.WindowManagerService.windowForClientLocked(WindowManagerService.java:8168)
05-25 08:26:03.010: WARN/WindowManager(18449):     at com.android.server.WindowManagerService$WindowState$DeathRecipient.binderDied(WindowManagerService.java:7026)
05-25 08:26:03.010: WARN/WindowManager(18449):     at android.os.BinderProxy.sendDeathNotice(Binder.java:385)
05-25 08:26:03.010: WARN/WindowManager(18449):     at dalvik.system.NativeStart.run(Native Method)
05-25 08:26:03.010: INFO/WindowManager(18449): WIN DEATH: null
05-25 08:26:03.020: INFO/ActivityManager(18449): Start proc uk.co.randomicon.rstb for activity uk.co.randomicon.rstb/.TreeBuilderActivity: pid=19565 uid=10069 gids={1015}
任何关于从哪里开始戳的想法都将受到感激

编辑:这是由于我在清单中设置了android:stateNotNeeded=“true”造成的。虽然我不需要状态,但这导致Android决定最好重新启动我的应用程序,前提是用户需要。以下是一些有用的信息:

当活动重新启动时——如果运行 前台活动消失,系统将丢弃该活动,如果 它没有有效的保存状态(通常意味着它已暂停) 并给出了系统在启动之前的onSaveInstanceState结果 停顿)。一旦决定是否放弃该活动,它就会 将恢复堆栈顶部的所有活动。如果这是 你的一项活动——或者是因为你有另一项活动 崩溃了,或者说崩溃了,不知何故它是固定的暂停状态 --然后它将再次启动您的流程,以显示顶级活动


这可能是由于调用目标设备上不可用的系统API造成的。我遇到了类似的问题,然后试图在4.0.x设备上调用ActivityManager.MemoryInfo.totalMem。我没有收到任何编译错误,因为我的目标是4.2.2,并且在API16(4.1)中添加了ActivityManager.MemoryInfo.totalMem。

如果应用程序清单中有android:persistent=“true”,它将在被杀死时重新启动。

谢谢,好消息。只希望我能使用它:)我现在已经标记为有用,如果结果是固定的暂停,我会接受。结果是完美的信息,但不是我想的那部分。我意识到它提到如果没有有效的保存状态,就把它扔掉,只是我的清单中有android:stateNotNeeded=“true”。所以它总是认为重新启动它很好(因为技术上是这样)。接受你的回答,谢谢!同样,这是一个正确的想法,但需要一个不同的解决方案。启动新活动时,我使用了以下标志:Intent.FLAG_activity_new_TASK | Intent.FLAG_activity_CLEAR_TASK | Intent.FLAG_activity_EXCLUDE_FROM_RECENTS。这将在新线程上启动任务,并确保所有先前出现的应用程序都从后台退出。