When app.exitApp() is called on multi-page app, pass to previous pages in stack and close them too.

This commit is contained in:
Bryce Curtis 2011-09-28 21:52:17 -05:00
parent 025577c41d
commit 0f988717d0
2 changed files with 31 additions and 5 deletions

View File

@ -10,6 +10,7 @@ package com.phonegap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import java.util.HashMap;
@ -172,7 +173,8 @@ public class App extends Plugin {
* Exit the Android application.
*/
public void exitApp() {
((DroidGap)this.ctx).finish();
((DroidGap)this.ctx).setResult(Activity.RESULT_OK);
((DroidGap)this.ctx).onDestroy();
}
/**

View File

@ -155,6 +155,7 @@ public class DroidGap extends PhonegapActivity {
// Plugin to call when activity result is received
protected IPlugin activityResultCallback = null;
protected boolean activityResultKeepRunning;
private static int PG_REQUEST_CODE = 99;
// Flag indicates that a loadUrl timeout occurred
private int loadUrlTimeout = 0;
@ -715,6 +716,13 @@ public class DroidGap extends PhonegapActivity {
if (this.appView != null) {
// Make invisible
DroidGap.this.runOnUiThread(new Runnable() {
public void run() {
DroidGap.this.setVisible(false);
}
});
// Make sure pause event is sent if onPause hasn't been called before onDestroy
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
@ -727,6 +735,9 @@ public class DroidGap extends PhonegapActivity {
// Forward to plugins
this.pluginManager.onDestroy();
}
else {
this.finish();
}
}
/**
@ -788,19 +799,20 @@ public class DroidGap extends PhonegapActivity {
intent.putExtra(key, (Integer)value);
}
}
}
super.startActivityForResult(intent, PG_REQUEST_CODE);
} catch (ClassNotFoundException e) {
e.printStackTrace();
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
this.startActivity(intent);
}
}
else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
}
this.startActivity(intent);
}
// Finish current activity
if (clearPrev) {
@ -1239,6 +1251,7 @@ public class DroidGap extends PhonegapActivity {
if (this.ctx.callbackServer != null) {
this.ctx.callbackServer.destroy();
}
this.ctx.finish();
}
}
@ -1389,6 +1402,17 @@ public class DroidGap extends PhonegapActivity {
*/
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
// If a subsequent DroidGap activity is returning
if (requestCode == PG_REQUEST_CODE) {
// If terminating app, then shut down this activity too
if (resultCode == Activity.RESULT_OK) {
this.setResult(Activity.RESULT_OK);
this.onDestroy();
}
return;
}
IPlugin callback = this.activityResultCallback;
if (callback != null) {
callback.onActivityResult(requestCode, resultCode, intent);