“RuntimeException: Performing pause of activity that is not resumed”

僤鯓⒐⒋嵵緔 提交于 2019-12-03 05:42:01

问题


(I see a similar question on stackoverflow, but the answer there is not a true answer, and the context of the problem is a bit different too.)

"java.lang.RuntimeException: Performing pause of activity that is not resumed"

I develop a game application (which uses both normal Views and GLSurfaceView). If I turn on and off my phone display very fast, I can cause this exception sometimes (thrown by ActivityThread ), but my application is running normally after the exception. My app is a landscape one, and this is correctly set in the manifest as well (including orientation and configchanges as well).

Is this OK?

It's a RuntimeException thrown by ActivityThread under the application name of my application, but it doesn't terminate my app.


回答1:


I've just had this problem because I was calling activity.recreate() (or .finish() and .startActivity() - depending on android version). Of course, you would only call those functions because you want to reload language, reset orientation and similar stuff that you can only do with activity recreation.

You can't call those functions (.finish() or .recreate()) from onResume() though. If you do, you will receive the mentioned non-fatal exception.

I "solved" the issue by delaying the .recreate() call for one millisecond so that the activity gets properly resumed and is only then killed.

  Handler handler = new Handler();
  handler.postDelayed(new Runnable()
  {
    @Override
    public void run()
    {
      log.i("TX.refresh", "Switching to %s from %s", lang, lang);
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
      {
        ctx.finish();
        ctx.startActivity(ctx.getIntent());
      } else ctx.recreate();
    }
  }, 1);


来源:https://stackoverflow.com/questions/10844112/runtimeexception-performing-pause-of-activity-that-is-not-resumed

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