PDA

View Full Version : Navigation View + TabPanel + Routing (Back button Android)



hotdp
16 May 2012, 5:44 AM
Hi,
The problem I am facing is the back button on Android.

My main layout is a TabPanel, with different NavigationViews for each Tab. So each time I change a Tab I add this to the history. When I go down in a NavigationView I will also add this to the history.

The problem is when I go back from a NavigationView and are on NavigationView index 0. When I then press back it will not exit the app (I believe this is standard Android when you get to the root) insteed it will do all the TabPanel changes and other events I have done and will only exit when the whole history is done.

Because it only adds to History and I can't "clear" this browser history when I change Tab in the TabPanel.
How should I solve this problem? I have multiple Applications with this setup and problem?

mitchellsimoens
18 May 2012, 6:11 AM
There isn't much you are going to be able to do. Like you said, you have to press back many times to clear out the whole history before the browser exits. This is browser behavior and not much you can do about it.

hotdp
30 May 2012, 11:23 PM
Is it not possible to do some "tweaks" with
window.history.replaceState ?

mitchellsimoens
31 May 2012, 2:11 AM
replaceState will only update the most recent entry not previous entries in the stack.

DeepShah
31 May 2012, 10:25 PM
You can put following code in the condition when you wants to exit the application.
In your problem you can check it the NavigationView index is 0 then exit application by putting following code in that condition.


code : navigator.app.exitApp();


For this you have to make apk that includes phonegap because this "navigator" is object of phonegap.

hotdp
31 May 2012, 10:31 PM
You can put following code in the condition when you wants to exit the application.
In your problem you can check it the NavigationView index is 0 then exit application by putting following code in that condition.


code : navigator.app.exitApp();


For this you have to make apk that includes phonegap because this "navigator" is object of phonegap.

But it is a web-app.

SebasSP
1 Jun 2012, 12:19 AM
One solution could be that you keep track of how many url changes there have been. Then when the user goes back and you want to exit the app, you would do:
window.history.go(-numberOfChanges)

hotdp
1 Jun 2012, 12:23 AM
One solution could be that you keep track of how many url changes there have been. Then when the user goes back and you want to exit the app, you would do:
window.history.go(-numberOfChanges)

I will try that! So you don't think there is a maximum (numberOfChanges) ?

SebasSP
1 Jun 2012, 12:55 AM
As far as I can tell there is no maximum, although trying to go back more urls than there are in the current tab history session will just do nothing.