如何修复 Android Widget 的“进程错误”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3253676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:18:51  来源:igfitidea点击:

How to fix "process is bad" error for an Android Widget?

androidandroid-widget

提问by wligtenberg

I have developed an Android Widget, and it was working fine. I added some extra functionality and pushed an update through the Android Market. Now people are complaining that it doesn't work anymore.

我开发了一个 Android 小部件,它运行良好。我添加了一些额外的功能并通过 Android Market 推送更新。现在人们抱怨它不再起作用了。

The error I see in the logs is:

我在日志中看到的错误是:

07-14 10:33:44.016: WARN/ActivityManager(78): Unable to launch app ... 
for broadcast Intent { act=android.appwidget.action.APPWIDGET_ENABLED 
cmp=... }: process is bad 
07-14 10:33:44.026: WARN/ActivityManager(78): finishReceiver called 
but none active 
07-14 10:33:44.026: WARN/ActivityManager(78): Unable to launch app ... 
for broadcast Intent { act=android.appwidget.action.APPWIDGET_UPDATE 
cmp=... (has extras) }: process is bad 
07-14 10:33:44.036: WARN/ActivityManager(78): finishReceiver called 
but none active 

I have searched, but I cannot find anywhere what the process is bad error means, so I have no clue on how to fix it. Restarting the phone (or emulator) makes the error go away, however, that is not what I want my users to do. Could someone please help me to explain what the cause of the error is and how to fix it?

我已经搜索过,但我找不到任何过程是错误的错误意味着什么,所以我不知道如何修复它。重新启动手机(或模拟器)会使错误消失,但是,这不是我希望我的用户做的事情。有人可以帮我解释错误的原因是什么以及如何解决它吗?

采纳答案by mobibob

I am having the same problem and my current theory is that the appWidget crashed and when it was restarted it had the same bad persistent data that made it crash each time it was restarted. When this happens too often, the appWidget is "force stopped" by the OS. My band aid is to have a touch event that is "setOnClickPending" that the user will touch (out of frustration if necessary) and that will be processed internal to the appWidget and reset the appWidget.

我遇到了同样的问题,我目前的理论是 appWidget 崩溃了,当它重新启动时,它具有相同的错误持久数据,导致每次重新启动时它都会崩溃。当这种情况经常发生时,操作系统会“强制停止”appWidget。我的创可贴是有一个触摸事件,它是“setOnClickPending”,用户将触摸它(必要时出于沮丧)并且将在 appWidget 内部进行处理并重置 appWidget。

回答by Vituel

Happened to me when my BroadcastReceiver was repeatedly leaking an exception causing the system to kill my app. The next calls to the receiver would result in the "process is bad" logs.

当我的 BroadcastReceiver 反复泄漏导致系统终止我的应用程序的异常时发生在我身上。对接收器的下一次调用将导致“进程错误”日志。

The solution in my case was making sure no exceptions leak from the BroadcastReceiver.

在我的案例中,解决方案是确保 BroadcastReceiver 没有异常泄漏。

Those are the logs when the app is killed (try looking for them and finding the cause):

这些是应用程序被终止时的日志(尝试查找它们并找到原因):

W/ActivityManager﹕ Process com.company.app has crashed too many times: killing!
I/ActivityManager﹕ Killing proc 9344:com.company.app/u0a10239: crash

回答by NPike

I just experienced this myself right before packaging for the market place. I was following the guidelines and added the android:label="@string/app_name" attribute to the application element in my manifest...

在为市场包装之前,我自己刚刚经历了这一点。我遵循了准则并将 android:label="@string/app_name" 属性添加到我的清单中的应用程序元素...

  1. Uninstall your app
  2. Reboot phone/emulator
  3. Push new app without this attribute
  1. 卸载您的应用
  2. 重启手机/模拟器
  3. 推送没有此属性的新应用

Viola! Works for me now!

中提琴!现在对我有用!

EDIT: To match comments.

编辑:匹配评论。

回答by Dan J

I hit a process is baderror on my HTC Sensation OS 2.3.4 after removing the INTERNETpermission from my AndroidManifest.xml.

从我的 AndroidManifest.xml 中process is bad删除INTERNET权限后,我在 HTC Sensation OS 2.3.4 上遇到了错误。

W/ActivityManager( 253): Unable to launch app MY_DOMAIN.flashback/10132 for broadcast Intent { act=android.intent.action.PHONE_STATE flg=0x20000000 (has extras) }: process is bad

W/ActivityManager(253):无法为广播 Intent { act=android.intent.action.PHONE_STATE flg=0x20000000 (has extras) } 启动应用程序 MY_DOMAIN.flashback/10132:进程不好

I carefully tried lots of different workarounds, and I found the only way to fix was:

我仔细尝试了许多不同的解决方法,我发现唯一的解决方法是:

  • Uninstall the app through Settings -> Applications.
  • Remove the battery from the phone (using the Android "Power off" menu did notwork).
  • Turn device on again.
  • Install the APK again using adb install <myapp>.
  • 通过设置 -> 应用程序卸载应用程序。
  • 从手机取下电池(使用Android“关机”菜单中没有工作)。
  • 再次打开设备。
  • 使用adb install <myapp>.

I want to take this opportunity to list what did NOTwork for me (as there seems to a lot of FUD about how to fix this error):

我想借此机会向列表什么也不要为我工作(因为似乎有一个关于如何解决这个错误很多FUD的):

  • Uninstall app, reboot using Android phone menu (press and hold on button and choose "Power off"), turn on again, reinstall.
  • Uninstall, use adb kill-server, then adb start-server, reinstall.
  • Uninstall, run adb shellthen ps, this didn't show my app running at all.
  • Uninstall, do a clean build in Eclipse, reinstall.
  • 卸载应用程序,使用 Android 手机菜单重启(按住按钮并选择“关机”),再次打开,重新安装。
  • 卸载,使用adb kill-server,然后adb start-server,重新安装。
  • 卸载,adb shell然后运行ps,这根本没有显示我的应用程序正在运行。
  • 卸载,在 Eclipse 中进行干净构建,然后重新安装。

I wonder if the underlying problem was caused by my app getting smaller in size. I think it used to unpack to flashback-1.apkand flashback-2.apkon the device, whereas now it is only unpacking to a single flashback-1.apk.

我想知道根本问题是否是由我的应用程序变小引起的。我认为它用来解压缩到flashback-1.apk,并flashback-2.apk在设备上,而现在它只是打开包装到一个单一的flashback-1.apk

回答by tsinyun

I just get this error. I fix the error and I remove some source code invoking from OnConnectionReceiver.onReceiver(), Maybe the invocation will cost some time.

我只是收到这个错误。我修复了错误并删除了一些从 中调用的源代码OnConnectionReceiver.onReceiver(),也许调用会花费一些时间。

回答by Jacob L

I faced this problem. the reason was that the WLAN call wifi.getConnectionInfo().getScanResults(); could return a null instead of an empty list in some occations. I found this after logging the logcat for several hours. When the application encountered an error and crashed, a touch on the widget would give me the same "bad process" error you mention here as the intent did not reopen the app, but it gets stuck in a crashed state. Guess it it just the way Android deals with a crashed widget.

我遇到了这个问题。原因是 WLAN 调用 wifi.getConnectionInfo().getScanResults(); 在某些情况下可能会返回 null 而不是空列表。我在记录 logcat 几个小时后发现了这一点。当应用程序遇到错误并崩溃时,触摸小部件会给我带来与您在此处提到的相同的“错误进程”错误,因为意图没有重新打开应用程序,但它会卡在崩溃状态。猜猜它就像 Android 处理崩溃的小部件的方式一样。

回答by Record413123

i got mine fixed like this:

我这样固定我的:

uninstall the application and install it again.

卸载应用程序并重新安装。

i got this error when i installed a "test" application with the same package name and messed up something in the app cache data or somewhere.

当我安装了一个具有相同包名的“测试”应用程序并且在应用程序缓存数据或某处搞砸了一些东西时,我得到了这个错误。

回答by Allen Luce

The "process is bad" is due to multiple crashes of the app (or BroadcastReceiver, Service, or other component). After a few of these the system decides it's fed up with that behavior and prevents the process from starting again.

“进程不好”是由于应用程序(或 BroadcastReceiver、Service 或其他组件)多次崩溃。在其中几次之后,系统决定它厌倦了该行为并阻止该过程再次启动。

A reboot will clear the crash count but it can also be cleared by killing the system server:

重新启动将清除崩溃计数,但也可以通过杀死系统服务器来清除它:

adb shell killall system_server

This will effectively do a "soft reboot." I find it much quicker than an actual reboot.

这将有效地进行“软重启”。我发现它比实际重新启动要快得多。

回答by sorry_I_wont

This worked for me! Change your implicit intent to explicit intent, because starting Oreo implicit intents don't run in background! So basically when creating your Intent object, pass in the class name you want to start. https://developer.android.com/about/versions/oreo/background.html

这对我有用!将您的隐式意图更改为显式意图,因为启动 Oreo 隐式意图不会在后台运行!所以基本上在创建你的 Intent 对象时,传入你想要启动的类名。 https://developer.android.com/about/versions/oreo/background.html

回答by abeboparebop

Somewhat off-topic, but in some Android devices one can reproducibly cause this failure by writing an app which creates an UncaughtExceptionHandlerin onCreateto restart the app after a crash, and then does something to cause an unhandled exception (either throw a RuntimeException, or do something that causes an NullPointerException, or whatever). Some example code is given below.

有点离题,但在某些 Android 设备中,可以通过编写一个应用程序来重复地导致此故障,该应用程序在崩溃后创建一个UncaughtExceptionHandlerinonCreate以重新启动应用程序,然后执行某些操作以导致未处理的异常(抛出一个RuntimeException,或执行某些操作导致NullPointerException,或其他)。下面给出了一些示例代码。

I have tried this on two devices: a Samsung Galaxy Tab 2, and a Verizon Ellipsis 7. With the Tab 2, I couldn't cause the issue while I was running the app from Eclipse -- it would crash and restart repeatedly and never be killed. Instead, I had to export the app to apk, install via adb, start the app, and after 4-8 crashes and restarts, Android would kill the app with the error message above (Process com.buggy.app has crashed too many times: killing!).

我已经在两台设备上尝试过这个:三星 Galaxy Tab 2 和 Verizon Ellipsis 7。使用 Tab 2,我在从 Eclipse 运行应用程序时无法导致问题——它会反复崩溃和重启,永远不会被杀。相反,我必须将应用程序导出到 apk,通过 adb 安装,启动应用程序,在 4-8 次崩溃并重新启动后,Android 将终止应用程序并显示上述错误消息 ( Process com.buggy.app has crashed too many times: killing!)。

With the Ellipsis 7, I was never able to reproduce the issue. The buggy app would repeatedly crash and restart, and the OS never killed it even after 10 minutes of this.

使用 Ellipsis 7,我永远无法重现该问题。有问题的应用程序会反复崩溃和重新启动,即使在 10 分钟之后,操作系统也从未将其杀死。

Sample code for repeatedly crashing app:

反复崩溃应用程序的示例代码:

public void onCreate(Bundle savedInstanceState) {
  mContext = this.getApplicationContext();

  UncaughtExceptionHandler uehandler = new Thread.UncaughtExceptionHandler() {

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {

      // restart app after 100 milliseconds
      PendingIntent myActivity = PendingIntent.getActivity(mContext, 0,
          new Intent(mContext, MyActivity.class),
          PendingIntent.FLAG_ONE_SHOT);
      AlarmManager alarmManager = (AlarmManager) 
          mContext.getSystemService(Context.ALARM_SERVICE);
      alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 100,
          myActivity);

      System.exit(2);

      // re-throw critical exception further to the os (important)
      Thread.getDefaultUncaughtExceptionHandler().uncaughtException(thread, ex);
    }
  };
  Thread.setDefaultUncaughtExceptionHandler(uehandler);

  throw new RuntimeException("Crash the app!");
}