You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Grayson Kleine (JIRA)" <ji...@apache.org> on 2016/03/01 09:48:18 UTC

[jira] [Commented] (CB-10705) Backbutton not working when an error page is set in cordova

    [ https://issues.apache.org/jira/browse/CB-10705?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15173452#comment-15173452 ] 

Grayson Kleine commented on CB-10705:
-------------------------------------

I think you are right in relation to that issue. I don't exactly know which path his code is traversing that is making cordova break but I would like to provide you with a bit more of information but my issue. I would like to make the remark that whenever pluginManager.init() is called and the appPlugin variable in CordovaWebViewImpl is not reset js events will break (like the back button). In my description I said to add a listener for the backbutton event in the error page. This is so to facilitate debugging, etc. But it is not a required step (adding the listener in that page). If you don't add the listener but navigate let's say back to the page you were before getting to the error page, the back button will still be broken. This is again because the appPlugin variable was set 3 pages earlier and was never reset after the call pluginManager.init(). Because of this the cordova.js code will be expecting a result from lets say channel with id CordovaCore:00000003 but the java code will be using channel with id CordovaCore:00000001 and again this is because the appPlugin variable was not reset. So the solution here is or always reset the appPlugin variable after the call to pluginManager.init() or never have a reference to the CorePlugin outside the plugin manager as again as soon as the plugin manager needs to reinitialize things will break.

> Backbutton not working when an error page is set in cordova
> -----------------------------------------------------------
>
>                 Key: CB-10705
>                 URL: https://issues.apache.org/jira/browse/CB-10705
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 3.5.0
>         Environment: android 4.4.4 using cordova 6 
>            Reporter: Grayson Kleine
>              Labels: triaged
>
> The issue is that when you have the an error page set to be displayed in the cordova config xml and you get an error and the user is on that page the backbutton hardware key will not work anymore.
> This is how to reproduce the issue.
> Preparation:
> You need atleast 2 page one normal page and 1 error page
> Turn off the wifi (so you will get error -2 (easy to test and reproduce))
> One page 1
> The a link on page one to google or some other site.
> Add a listener to the backbutton event (js) with something like alert('1') or console.log('1').
> One the error page
> Add a listener to the backbutton event, again set the function to do something that you can easily see like an alert.
> Compile and start the application in android.
> Execution:
> On the first page click the hardware back button, you should see an alert if you have set the function to display an alert.
> Now press the link
> You should now be on the error page
> Press the hardware back button, nothing happens.
> Issue and Solution:
> After some debugging I found out wat was going on:
> When an error page should be displayed the function loadUrlIntoView in the CordovaWebViewImpl class will be called. In normal page navigation the pluginManager is not reinitialized by the CordovaWebViewImpl but that is something that happens when an error page is displayed. The problem here is that while the pluginManager was reinitialized the variable hold the reference to the CoreAndroid object was not. Meaning that after the initialization  CordovaWebViewImpl would try to fire js events using the wrong reference to the core plugin (CoreAndroid). 
> So the solution in here is to set appPlugin = null just before the pluginManager is reinitialized.
> If this is accepted as a bug and my proposed change is accepted  I would like to make a pull request my self.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org