cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikael Ståldal (JIRA) <j...@apache.org>
Subject [jira] [Created] (CB-6391) Should be possible to intercept exiting of web app
Date Wed, 02 Apr 2014 15:33:14 GMT
Mikael Ståldal created CB-6391:
----------------------------------

             Summary: 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


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):

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






--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message