Skip to content

Commit

Permalink
android emit app pause resume
Browse files Browse the repository at this point in the history
Android OS doesn’t stop threads when the app is on background. In order
to provide the same experience, we will be firing pause and resume
events onStart and onStop for Android.
  • Loading branch information
obastemur committed Jul 20, 2015
1 parent 2caaa33 commit 8641f8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions app/jxcore_cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ if (isAndroid) {
jxcore.tasks.register(process.setPaths);
jxcore.tasks.register(process.registerAssets);
jxcore.tasks.register(extendFS);

JXMobile('JXcore_Device_OnResume').registerToNative(function(){
process.emit('resume');
});

JXMobile('JXcore_Device_OnPause').registerToNative(function(){
process.emit('pause');
});
} else {
jxcore.tasks.register(process.setPaths);
}
Expand Down
8 changes: 4 additions & 4 deletions src/android/java/io/jxcore/node/jxcore.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ public void run() {
return true;
}

@Override
public void onPause(boolean multitasking) {
public void onStart(boolean multitasking) {
super.onPause(multitasking);
jxcore.CallJSMethod("JXcore_Device_OnPause", "{}");
app_paused = true;
}

@Override
public void onResume(boolean multitasking) {
public void onStop(boolean multitasking) {
super.onResume(multitasking);
jxcore.CallJSMethod("JXcore_Device_OnResume", "{}");
app_paused = false;
}

Expand Down

0 comments on commit 8641f8f

Please sign in to comment.