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