Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back button not working/bug #42

Open
hereforhelp opened this issue Jan 22, 2015 · 2 comments
Open

Back button not working/bug #42

hereforhelp opened this issue Jan 22, 2015 · 2 comments

Comments

@hereforhelp
Copy link

The back button event listener is not working after adding webview-plus plugin for android.

Steps to reproduce:

  1. cocoonjs create backbuttontest

  2. cd backbuttontest

  3. cocoonjs platform add android

  4. cocoonjs plugin add com.ludei.webview.plus

  5. Edit www/js/index.js, add "document.addEventListener('backbutton', function(){alert("Back Button Pressed!");});" into onDeviceReady function so that it looks like this:

onDeviceReady: function() {
app.receivedEvent('deviceready');
document.addEventListener('backbutton', function(){alert("Back Button Pressed!");});
},

  1. cocoonjs run android

When the app is launched, press the back button and the app will exit without triggering the event listener.
However, if you launch the app, press the home button (to bring it to background), open the app again (from background), press the back button and the event listener will get triggered.

Am I doing something wrong or what?

@kianenigma
Copy link

Same Problem . Any one With a Solution ?

@hereforhelp
Copy link
Author

I had found a quick fix for it.

Navigate to:
\platforms\android\CordovaLib\src\org\apache\cordova\CordovaActivity.java

Add the following function into CordovaActivity Class:
@OverRide
public void onBackPressed() {
appView.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
}

Find and Comment the following function call (Not sure if this step is needed):
this.getWindow().getDecorView().requestFocus();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants