Prevent Android “process is bad” error

馋奶兔 提交于 2019-12-03 05:11:32

Good Chance is that it has to do with the handling of the activity's lifecycle.

It reminds me of a case I recently solved without fully understanding it because the documentation is not very specific on what you can rely on after onStop() is called on your Activity. And what exactly you shouldn't do...

So I can only give you some hints:

If my guess is right, you have problem with not being properly restored, when your App is (partially) removed from memory. Try setting the limit for background-Apps in the developer-settings to "none". I suspect that with this setting your problem will be completly reproducable when puting it to background. Otherwise you probably can stop reading here.

I had a thread that kept on running after onStop() that also kept some references. Stopping the thread in onPause() and also waiting for it to finsh solved my problem. I also needed to sync my onStop() because blocking onPause() resulted in onStop() coming in paralell. I also needed to move some of my initilization from onCreate() to onResume(). But that was quite obvious once I figured out at what to tear down in onResume() and onStop().

Probably the tipp with the static goes in the same direction.

The "process is bad" error happens after your service crashes a couple times. The system prevents it from coming back up and instead prints that message. You can clear the crash count by rebooting or more quickly by killing the system server:

adb shell killall system_server

This is effectively a "soft reboot" and will kill/restart any processes you've got going.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!