[ https://issues.apache.org/jira/browse/CB-6391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13979854#comment-13979854 ]
Mikael Ståldal commented on CB-6391: ------------------------------------ I have signed and submitted the CLA now. > Should be possible to intercept exiting of web app > -------------------------------------------------- > > Key: CB-6391 > URL: https://issues.apache.org/jira/browse/CB-6391 > Project: Apache Cordova > Issue Type: Improvement > Components: Android > Affects Versions: 3.4.0 > Environment: Android > Reporter: Mikael Ståldal > Assignee: Andrew Grieve > Labels: android, webview > > I am integrating Cordova into an existing Android app, using CordovaWebView. > When the web app exits (due to pressing back button beyond history), the > CordovaWebView invokes finish() on the Activity. This is not always what you > want. If you use Fragments, you might want to swap fragments rather than exit > the Activity. > Here is a patch to fix this (based on 3.4.0): > {noformat} > diff --git a/org/apache/cordova/CordovaActivity.java > b/org/apache/cordova/CordovaActivity.java > index 9f8b020..a6d3502 100755 > --- a/org/apache/cordova/CordovaActivity.java > +++ b/org/apache/cordova/CordovaActivity.java > @@ -829,6 +829,7 @@ public class CordovaActivity extends Activity implements > CordovaInterface { > } > } > > + @Override > /** > * End this activity by calling finish for activity > */ > diff --git a/org/apache/cordova/CordovaInterface.java > b/org/apache/cordova/CordovaInterface.java > index 59ed486..262d7ca 100755 > --- a/org/apache/cordova/CordovaInterface.java > +++ b/org/apache/cordova/CordovaInterface.java > @@ -69,4 +69,11 @@ public interface CordovaInterface { > * Returns a shared thread pool that can be used for background tasks. > */ > public ExecutorService getThreadPool(); > + > + /** > + * Called when the web app exits. > + * Normally, you would just call {@link android.app.Activity#finish()}, > + * but a sophisticated application might want to do something else like > swapping fragments. > + */ > + public void endActivity(); > } > diff --git a/org/apache/cordova/CordovaWebView.java > b/org/apache/cordova/CordovaWebView.java > index 4dfeb55..28e9561 100755 > --- a/org/apache/cordova/CordovaWebView.java > +++ b/org/apache/cordova/CordovaWebView.java > @@ -760,7 +760,7 @@ public class CordovaWebView extends WebView { > //this.activityState = ACTIVITY_EXITING; > //return false; > // If they hit back button when app is initializing, > app should exit instead of hang until initi > - this.cordova.getActivity().finish(); > + this.cordova.endActivity(); > } > } > } > {noformat} -- This message was sent by Atlassian JIRA (v6.2#6252)