Commit 194bc293 authored by Sharaf Zaman's avatar Sharaf Zaman
Browse files

Bugfix: crash when File->Quit is used or..

if app is killed. This happens on ChromeOS and few other devices which
let the process live a beyond the Activity, so when the control reaches
exit() on C++ side -- it crashes while cleaning global static state.

BUG:426092
parent de1911c1
......@@ -19,6 +19,7 @@
package org.krita.android;
import android.util.Log;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
......@@ -32,7 +33,9 @@ package org.krita.android;
public class MainActivity extends QtActivity {
public boolean isStartup = true;
private boolean isStartup = true;
private Thread mDocSaverThread;
private String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -84,13 +87,41 @@ public class MainActivity extends QtActivity {
// onPause() _is_ called when the app starts. If the native lib
// isn't loaded, it crashes.
if (!isStartup) {
JNIWrappers.saveState();
synchronized(this) {
// let's not block the Android UI thread if we return to the app quickly
mDocSaverThread = new Thread(new Runnable() {
@Override
public void run() {
JNIWrappers.saveState();
}
});
mDocSaverThread.start();
}
}
else {
isStartup = false;
}
}
@Override
public void onDestroy() {
synchronized (this) {
if (mDocSaverThread != null) {
try {
mDocSaverThread.join();
} catch (InterruptedException e) {
Log.e(TAG, "Interrupted :" + e.getMessage());
}
}
}
// Hack or not, I'm not sure. Beyond this, Qt will invoke libc's exit()
// which doesn't kill our global static properly. So, because Qt app *is*
// supposed to terminate now, this should perfectly safe.
android.os.Process.killProcess(android.os.Process.myPid());
super.onDestroy();
}
@Override
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && getActionBar() != null &&
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment