"RuntimeException:执行未恢复的活动的暂停" [英] "RuntimeException: Performing pause of activity that is not resumed"

查看:98
本文介绍了"RuntimeException:执行未恢复的活动的暂停"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我在stackoverflow上看到了类似的问题,但是答案没有一个真正的答案,问题的背景也有所不同.)

(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:执行未恢复的活动暂停"

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

我开发了一个游戏应用程序(它同时使用普通Views和GLSurfaceView).如果我非常快地打开和关闭手机显示屏,有时会导致此异常(由ActivityThread抛出),但是在发生异常后,我的应用程序可以正常运行.我的应用程序是一款横向应用程序,它也可以在清单中正确设置(也包括方向和配置更改).

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).

这样可以吗?

这是ActivityThread在我的应用程序的应用程序名称下引发的RuntimeException,但它不会终止我的应用程序.

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

推荐答案

我刚刚遇到了这个问题,因为我正在调用activity.recreate()(或.finish()和.startActivity()-取决于android版本) . 当然,您仅会调用这些函数是因为您想重新加载语言,重置方向以及类似的事情,而这些事情只能通过活动娱乐来完成.

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.

但是您不能从onResume()调用那些函数(.finish()或.recreate()). 如果这样做,您将收到提到的非致命异常.

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

我通过将.recreate()调用延迟一毫秒来解决"该问题,从而使活动得以正确恢复,然后才被终止.

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);

这篇关于"RuntimeException:执行未恢复的活动的暂停"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆