Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"RuntimeException: Performing pause of activity that is not resumed"

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

like image 579
Thomas Calc Avatar asked Jun 01 '12 03:06

Thomas Calc


1 Answers

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); 
like image 173
velis Avatar answered Oct 07 '22 16:10

velis