Hardware backbutton not working beta.6


#1

i updated my project to beta.6,
but hardware backbutton event not working .
always closing app .

 document.addEventListener('backbutton',function(){
		  alert(1);
		  return;
	  });

i tried another method but not working again .

 document.addEventListener('backbutton',function(e){
       e.preventDefault();
	  });

#2

Plase help , my app is closing always .


#3

If I remember well Ionic team planned this for beta 5.

And yes this is still big issue which affects my project as well - 2 weeks until presentation to client :frowning:

P.S.

Yep it was planned for phase 5 and commented as fixed:

https://github.com/driftyco/ionic/issues/5071

@OmarHassan25 : @adamdbradley already fixed in git, milestone is set for beta 5, so guessing it will be included there.

#4

I have beta.6 installed and the Android back button does function properly so long as there are additional pages in the navigation stack. On the other hand, if you’re at a root page then the hardware button will close the app which is not the preferred result IMO. I think when you’re on a root page the back button shouldn’t do anything, or at the most it should us a prompt to ask the user if they want to close the app or not.


#5

can you share your code please


#6

Same issue here. Back button closes the app on beta.6. Am I supposed to add any additional code?

Current environment:
Cordova CLI: 6.0.0
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.1
Ionic Version: 2.0.0-beta.6
Ionic CLI Version: 2.0.0-beta.19
Ionic App Lib Version: 2.0.0-beta.9
OS: Windows 7 SP1
Node Version: v0.12.7


#7

Never ever use beta-tools for client projects :slight_smile:


#8

Lesson learned a years ago but this wasn’t my decision but company’s :frowning:


#9

And to be honest - excellent framework - saved me a log of headaches - those small thingies can be worked out this or that way :slight_smile:


#10

It sure is, but it’s still in beta. I really enjoy working in Ionic2, but I wouldn’t use it for production apps yet.

But we’re getting there :slight_smile: The only way to get it there, is by testing & reporting errors.


#11

any update , i cant fix this problem?


#12

For me it works in beta 6 with exception on modals. That should be fixed.
Once you return to root page it close app.


#13

Does not work correctly in beta 7! The event can be received but no possibility to interfere. This should be made possible by Ionic to kill the app on exit. Actually the problem is on root - the app leaves but the app can still be found in the app list. When activating it again, the app restarts(?) but without splash screen. As Ionic 2 takes actually too long to load, an ugly white screen is visible for several seconds. IMO opinion this is also related somehow to Crosswalk. Has anybody an idea on this?


#14

I fixed it .

Find node_modules\ionic-angular\components\app\app.js Line :32

remove this function :

platform.backButton.subscribe(function () {
            var activeNav = _this.getActiveNav();
            if (activeNav) {
                if (activeNav.length() === 1) {
                    platform.exitApp();
                }
                else {
                    activeNav.pop();
                }
            }
        });

#15

This isn’t because of crosswalk. I’m not using it and having exactly the same white screen for few seconds - this part really needs optimisation.


#16

@lhteam thanks a lot!!! Yes, this works. Now it is possible to add own code in the event listener. IMO Ionic should remove this code.


#17

The problem seems that the app is not suspended correctly with the back button. Try to press the “home” button instead of the “back button”. Afterwards resume from the app list. There will be no white screen. Apart that the loading of Ionic 2 takes too long, I don’t think it is related to Ionic.


#18

@Vukasin The problem with the white screen can be reproduced with the simplest possible Cordova app (without Crosswalk and Ionic 2). Something seems to be wrong or we miss something. Anyhow, I filed an issue in the Cordova JIRA. As the JS of Ionic 2 is actually too heavy, the effect is visible very well. https://issues.apache.org/jira/browse/CB-11304


#19

To show the splash screen on relaunch to avoid the white screen after “back button” exit, this option is needed in config.xml:
<preference name="SplashShowOnlyFirstTime" value="false" />

For Crosswalk additionally I updated to plugin version 1.7.0 (I don’t know if really necessary - however this made it work).


#21

This is great!

Thanks a lot :smiley: