Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229274

this.platform.registerBackButtonAction doesn't work

$
0
0

in any event back button is close the app

Its obvios why the application is closing all the time.

{
this.rootPage=Welcome;
this.platformbegin(); //<- !
}

You are initializing the function when the app is starting.
Resulting in = App closes because of: this.platform.exitApp();

[The problem could be that your counter is NOT working and it just runs the else code! Maybe adding a console.log would show if the counter is really working or not.]

  this.platform.registerBackButtonAction(() => {
  if (this.counter == 0) {
    this.counter++;
    this.presentToast();
    setTimeout(() => { this.counter = 0 }, 2000)
  } else {
    // console.log("exitapp");
    this.platform.exitApp();
  }
}, 0)

Bind this code somewhere in your typescript but not in the initialized function.
(Idk if your counter is working or not Im asuming it works for now, but I see a mistake in here.)

Simply add an else if.

  this.platform.registerBackButtonAction(() => {
  if (this.counter == 0) {
    this.counter++;
    this.presentToast();
    setTimeout(() => { this.counter = 0 }, 2000)

  } else if(this.counter == 2){
    // console.log("exitapp");
    this.platform.exitApp();
  }
}, 0)

Im also not sure why this: 0) is present in the end of your codeline.
You also should be able to initialize it again with your function with this code.


If that doesn’t work. You might just add a Backbutton in the HTML yourself and create a function for it and bind this code to it just without this.platform.registerBackButtonAction(() => {

I hope this helps you out a bit. :blush::bird:


Viewing all articles
Browse latest Browse all 229274

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>