android - Android 中的 Spurious Death 是什么?

标签 android

我知道这听起来是个懒惰的问题..但我真的不知道这种情况是如何发生的,我在谷歌上也找不到太多相关信息。

背景:

这是一个带有 IPC 的应用程序:我有一个在单独进程中运行的服务。有时,服务被杀死了……但它并没有真正“正式死亡”,相反,我从 ActivityManager 得到了一个术语,叫做“虚假死亡”。发生这种情况时,服务的行为就像僵尸一样。它还活着,但并没有真正发挥作用。

04-12 10:03:37.935 728 830 I ActivityManager: Force finishing activity ActivityRecord{11eee41f u0 com.android.staging/com.android.activities.MainActivity t8210} 04-12 10:03:37.937 728 830 I ActivityManager: Force stopping service ServiceRecord{291a4c9b u0 com.android.staging/com.android.services.CallService} 04-12 10:03:37.969 728 2563 W ActivityManager: Spurious death for ProcessRecord{27ecf545 11057:com.android.staging/u0a268}, curProc for 11057: null

最佳答案

违规行可以在这里找到: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/com/android/server/am/ActivityManagerService.java/#4858 (不同版本的Android L有不同的线路)

我假设您使用的是某种形式的 Android L,因为直到那时才添加特定的错误消息。

如果您在进程中运行 ContentProvider,ActivityManagerService 中的这两条注释可能会有所帮助:

9303                     // NOTE: there is still a race here where a signal could be
9304                     // pending on the process even though we managed to update its
9305                     // adj level.  Not sure what to do about this, but at least
9306                     // the race is now smaller.
9307                     if (!success) {
9308                         // Uh oh...  it looks like the provider's process
9309                         // has been killed on us.  We need to wait for a new
9310                         // process to be started, and make sure its death
9311                         // doesn't kill our process.

然后……

9317                         appDiedLocked(cpr.proc);

appDiedLocked 也可以从其他一些源文件调用:ActiveServices.java 和 ActivityStackSupervisor.java,一个取决于抛出的 DeadObjectException,另一个取决于 RemoteException。

appDiedLocked 看起来像这样

4853     final void appDiedLocked(ProcessRecord app, int pid, IApplicationThread thread) {
4854         // First check if this ProcessRecord is actually active for the pid.
4855         synchronized (mPidsSelfLocked) {
4856             ProcessRecord curProc = mPidsSelfLocked.get(pid);
4857             if (curProc != app) {
4858                 Slog.w(TAG, "Spurious death for " + app + ", curProc for " + pid + ": " + curProc);
4859                 return;
4860             }
4861         }

出于某种原因,curProc 与应用程序 ProcessRecord 不同,appDiedLocked 方法被缩短了。在您的例子中,由于某种原因,curProc 为空。

长话短说:您的进程死亡或被终止,并且某些状态或条件阻止 appDiedLocked 继续运行 killProcess 命令。您需要进行更多调查/记录以查明发生这种情况的原因。

如果你有一个你想要保持活跃的服务,除非你已经在做,我建议你给它附加一个状态栏通知,这样它被杀死的可能性就会降低。

关于android - Android 中的 Spurious Death 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29590251/

相关文章:

c# - 删除所有标记而不使用 map.clear() Google map - Xamarin

android - 带有 AppBarLayout 和工具栏的新 Android 设计库错误

java - 调用邮政编码 -- Android

android - ionic 清新剂 - 微调器未显示

android - 如何在使用 Android Universal Image Loader 将图片显示在 View 中之前调整图片大小?

android - 在 OSX 上使用 Make 为 Android 编译

Android BottomSheet 类似于 Share Sheet,底部有锚定 View

java - 在 Android Q 中无法从 "android.location.ILocationManager"找到方法 reportLocation()

android - 整个应用程序的单个警报对话框

java - 如何在触摸时不选中复选框