You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Andrew Grieve (JIRA)" <ji...@apache.org> on 2014/04/16 21:48:17 UTC

[jira] [Assigned] (CB-6391) Should be possible to intercept exiting of web app

     [ https://issues.apache.org/jira/browse/CB-6391?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrew Grieve reassigned CB-6391:
---------------------------------

    Assignee: Andrew Grieve

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