question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android 5, back button override is not working

See original GitHub issue

Hi,

cordova.plugins.backgroundMode.overrideBackButton();

is not working as expected. The icon shows for a fraction of a second and then the app stops working and the icon in the tray is no more.

I don’t have any other code except for a hello world app.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:16

github_iconTop GitHub Comments

6reactions
tlofanocommented, Mar 6, 2020

@ddduarte Something like this:

platform.ready().then(() => { 
    platform.registerBackButtonAction(() => { 
         if(nav.canGoBack()) {
            nav.pop();
         }
        else if(this.backgroundMode.isEnabled()) {
           this.backgroundMode.moveToBackground();
         }
    });
}
4reactions
ddduartecommented, Dec 11, 2017

I bettered my code.

  if(!this._backgroundMode.isEnabled()){
      this._backgroundMode.enable();
      this._backgroundMode.setDefaults({silent: true});
      this._backgroundMode.disableWebViewOptimizations();
     // this._backgroundMode.overrideBackButton();
  }

this._platform.registerBackButtonAction(() => {
  this._backgroundMode.moveToBackground();
});

this._backgroundMode.on('activate')
  .subscribe(() => {
    // your code
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android back button not working after onKeyUp() is overridden
Once the above method is added to an activity, the back button stops working but the other two buttons on the navigation bar...
Read more >
Provide custom back navigation - Android Developers
Back navigation is how users move backward through the history of screens they previously visited. All Android devices provide a Back button for ......
Read more >
Overriding Back Button in Xamarin.Forms Shell…
I've been working on trying to override the back button behavior on ... with the Android on-screen back button, this does not work...
Read more >
Disable/Override Back Button in Flutter - The Right Way (2022)
It may happen that when users use your app, they may accidentally press the back button in Android and get out of your...
Read more >
Overriding onBackPressed() (the Back Button) - YouTube
Learn how to override the onBackPressed() method in Android to require the user to press the back button twice to exit the app, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found