Back Button browse back

1,505 views
Skip to first unread message

Larsinger S.

unread,
Nov 20, 2011, 7:05:40 PM11/20/11
to phonegap
Hi,

one question ...
i'm developing on an App. for Android devices. I just switched to
Version 1.2.
in Phonegap Version 1.1 when i hit the back button i browse back.
In Version 1.2 this closes the App.
I see that there where issues in verion 1.1 with closing apps.
But how can i get the behavior of the back button from Version 1.1.

A short example. I'm on page one and go to page two and then to page
tree.
When i hit the back button i want to browse back to page two and then
one.

Thank a lot

az

unread,
Dec 3, 2011, 4:39:18 PM12/3/11
to phonegap
I'm having the same problem with PhoneGap 1.2 and jQuery Mobile 1.0.
Even if I'm a few pages in, clicking the Android back button exits
the app.

Any solutions?

thanks,
az


On Nov 20, 4:05 pm, "Larsinger S." <lars.schna...@googlemail.com>
wrote:


> Hi,
>
> one question ...
> i'm developing on an App. for Android devices. I just switched to
> Version1.2.
> in Phonegap Version 1.1 when i hit the back button i browse back.

> In Version1.2this closes the App.

Simon MacDonald

unread,
Dec 16, 2011, 12:51:30 PM12/16/11
to phon...@googlegroups.com
I've been playing around with some jQuery Mobile code to see if I can reproduce the back button problem you are having. Sadly, I can't seem to get it to fail. Can you post up some sample code so I can try it out?

Simon Mac Donald
http://hi.im/simonmacdonald


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Larsinger S.

unread,
Jan 20, 2012, 6:56:55 AM1/20/12
to phonegap
For Version 1.2 this works. Add this Code to your Main Activity.

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if(appView.canGoBack()){
appView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}

But the bug has been fixed in the new Version of PG. But if you have
to user 1.2 try this.

On 3 Dez. 2011, 22:39, az <alon...@gmail.com> wrote:
> I'm having the same problem with PhoneGap 1.2 and jQuery Mobile 1.0.
> Even if I'm a few pages in, clicking the Android back button exits
> the app.
>
> Any solutions?
>
> thanks,
> az
>
> On Nov 20, 4:05 pm, "LarsingerS." <lars.schna...@googlemail.com>

Darren McEntee

unread,
Jan 26, 2012, 1:07:24 PM1/26/12
to phon...@googlegroups.com
Hi,

Yes i have upgraded from 0.9.3 to 1.3.0 and i have the exact same issue.
I navigate from Index Screen > Screen 1 >  Screen  2.
If i use the back button, when i am on screen 2, it brings me back to the index screen instead of screen 2.

Any solutions for 1.3.0?
Thanks,
Darren.


Simon MacDonald

unread,
Jan 27, 2012, 12:37:28 PM1/27/12
to phon...@googlegroups.com
Hey everyone,

I really thought we had this one cracked wide open in 1.3.0 but upon further investigation we discovered a possible timing problem that could cause and issue with back page navigation. We spent about an hour on the phone going over the scenario and we think we've fixed the bug for good or at least until the 1.5.0 release.

On Tuesday you should be able to pick up PhoneGap 1.4.0 which will include the fix. And for those of you with jQuery it should work for you as well. 

Darren McEntee

unread,
Jan 31, 2012, 1:14:56 PM1/31/12
to phon...@googlegroups.com
Hi,

Just downloaded PG 1.4.0, added to the project lib (JS and Jar) and can just confirm that this issue still occurs :(
I working with Jquery Mobile.

Regards,
Darren.
--
Darren McEntee.
Owner/Developer, Visual Design.
www.visualdesign.ie

Office: +353.494365933
Mob:   +353.876439019
Skype: darren.mcentee
Registered in Ireland: 396707

Mikel

unread,
Jan 31, 2012, 2:13:37 PM1/31/12
to phonegap
Maybe I'm totally wrong about this but here is my take on what is
happening. This is also how I handled this issue as asked by the OP.

If I used JQM and don't set my anchor tags to rel-external it injects
the page into the DOM. Thus there is no history for the back button
to work its way through. Closing the app would be the next step back
as the device isn't aware that any pages had changed.

If I do set it to rel-external then it doesn't inject it but rather
treats it as a regular page load/change/whatever and now you have some
history for the back button to click through.

So if I used my device back button I will now go from page three, back
to two, then to one and then close the app.

On Jan 31, 1:14 pm, Darren McEntee <darren.mcen...@gmail.com> wrote:
> Hi,
>
> Just downloaded PG 1.4.0, added to the project lib (JS and Jar) and can
> just confirm that this issue still occurs :(
> I working with Jquery Mobile.
>
> Regards,
> Darren.
>
> On 27 January 2012 17:37, Simon MacDonald <simon.macdon...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > Hey everyone,
>
> > I really thought we had this one cracked wide open in 1.3.0 but upon
> > further investigation we discovered a possible timing problem that could
> > cause and issue with back page navigation. We spent about an hour on the
> > phone going over the scenario and we think we've fixed the bug for good or
> > at least until the 1.5.0 release.
>
> > On Tuesday you should be able to pick up PhoneGap 1.4.0 which will include
> > the fix. And for those of you with jQuery it should work for you as well.
>
> > Simon Mac Donald
> >http://hi.im/simonmacdonald
>
> --
> Darren McEntee.
> Owner/Developer, Visual Design.www.visualdesign.ie
>
> *Office: *+353.494365933
> *Mob:   *+353.876439019
> *Skype:** *darren.mcentee
> Registered in Ireland: 396707

Simon MacDonald

unread,
Jan 31, 2012, 3:09:47 PM1/31/12
to phon...@googlegroups.com
Wow, I don't know what to tell you. I've tested it on our app which goes 3 pages deep (no jQuery) and again with a second test app that goes a couple pages deep with jQuery. While I'm no where near a jQuery expert it appears to be working.

Can you work up a reproduction scenario for us to be able to test against?

Darren McEntee

unread,
Jan 31, 2012, 3:14:58 PM1/31/12
to phon...@googlegroups.com
For me, 

I'm using  rel = external also. 
I navigate from Index Screen > Screen 1 >  Screen  2.
If i use the back button, when i am on screen 2, it brings me back to the index screen instead of screen 1.

Really need to write a work around on this soon.

Simon MacDonald

unread,
Jan 31, 2012, 3:17:17 PM1/31/12
to phon...@googlegroups.com
Send me a real simple .html that demonstrates this and I'll work on it. Plus, let me know what version of jQuery you are using.

--

Darren McEntee

unread,
Feb 1, 2012, 10:58:33 AM2/1/12
to phon...@googlegroups.com
Code sent Simon, along with APK built with 1.4.0

Many thanks,
Darren. 

Darren McEntee

unread,
Feb 2, 2012, 6:31:57 PM2/2/12
to phon...@googlegroups.com
Tried everything on this, rebuilt my project, remove ALL libs and code, re-added one by one -- and still navigation skip issue.
Looks as thought ill need to revert back from 1.4.0 to phonegap 0.9.3, as that's the only version that the issue doesn't occur :(

Matthew N

unread,
Feb 2, 2012, 6:49:31 PM2/2/12
to phonegap
I have something to try, though it's not a fix so much as a work-
around. I use this with JQuery Mobile 1.0.1 and Jquery 1.6.4 with
Phonegap 1.4 on Android 2.3.3.

On each jquery mobile "Page" I specifiy "data-previous-page" which is
the place I expect the user to be directed to when the back button is
pressed, and if "data-previous-page" is not specified I just try to
use the history.back() call:


<div data-role="page" id="some-page" data-previous-page="#some-
previous-page"></div>


..and I have a function:


function handleBackButton() {
console.log("Handling Back Button");
if (($($.mobile.activePage).attr('data-previous-page') !==
undefined) || ($($.mobile.activePage).attr('data-previous-page') ==
"")) {
console.log("going back to " + $($.mobile.activePage).attr('data-
previous-page'));
window.location.href=$($.mobile.activePage).attr('data-previous-
page');
} else {
console.log('Using default back button behaviour');
history.back();
}
}


..and a listener:


document.addEventListener("backbutton", handleBackButton, false);

Darren McEntee

unread,
Feb 2, 2012, 7:02:05 PM2/2/12
to phon...@googlegroups.com
Thanks Matthew,
Will this work if i am using rel=external on pages?
I will give this a go in the morning.

Thanks for this.
Darren.

Simon MacDonald

unread,
Feb 3, 2012, 11:25:37 AM2/3/12
to phon...@googlegroups.com
Darren I have bits of your application and I can't reproduce. Can you
give me an detailed reproduction scenario? I start at index goto
index-main and then epl and I can back right out of the app. How do
you reproduce the issue?

Darren McEntee

unread,
Feb 4, 2012, 7:00:15 AM2/4/12
to phon...@googlegroups.com
Hi Simon, i will drop the detail in an email.
thanks,
Darren.

Darren McEntee

unread,
Feb 4, 2012, 7:21:49 AM2/4/12
to phon...@googlegroups.com
Hi Simon,

What happens is that i start the application, (index loads) then it sent to auto sent to index-main.
When on index-main you have multiple navigation options to select. When i select one of those options it will bring you to epl (for example).

So at that point i have navigated from index >> index-main >> epl.
The issue occurs when i am on epl (or any other selection page after index-main), and i use the back button. I should be brought back to index-main, but i am brought back to index instead, thus skipping index-main altogether.

If you then go into a few other leagues selections after navigating for a while, and hit the back button, it will work as normal.

What it should do:
index >> index-main >> epl. (navigating forward)
epl >> index-main >>  index. (navigating back via back button)

What actually happens:
index >> index-main >> epl. (navigating forward)
epl >> index. (navigating back via back button, skips index-main completely)

I hope that makes sense.
Thanks,
Darren.

Simon MacDonald

unread,
Feb 6, 2012, 8:40:17 PM2/6/12
to phon...@googlegroups.com
For anyone who is following this thread it has something to do with
the index.html automatically redirecting to index-main.html. Still
looking into it...

Darren McEntee

unread,
Feb 9, 2012, 6:52:35 AM2/9/12
to phon...@googlegroups.com
The auto forward just redirects to index-main via a delayed call.
But the main-index page loads like any other page, also there is no <body onload... call on index-html...

Darren McEntee

unread,
Feb 9, 2012, 12:43:47 PM2/9/12
to phon...@googlegroups.com
On another note, the auto redirect is performing like this...

        // If conn is 'WiFi connection'
else if (states[networkState] == 'WiFi connection') {
 connAlive = "1";
 $().toastmessage('showSuccessToast', 'Connection OK: <br /> ('+states[networkState]+') Conn: ('+connAlive+')');
          setTimeout('top.location="index-main.html";',3400);
 }

Can you see how this would be interfering with the phonegap backbutton navigation code?
It used to work fine on Phonegap v0.9.3, but once i upgraded to anything as far as v1.4, the issue would occur.
Regards,
Darren.

Mike

unread,
Feb 9, 2012, 2:59:29 PM2/9/12
to phonegap
I am having the same problem as reported. The back button is nothing
working right. Mine is a little different thought I am using JQM for
the back button. When I click on an item say Agenda and click back it
will work but if I click Agenda again and click back it will move to
the index page and not work. I can confirm that this is consistant
with all the links on the page.

(I should add that I have tried PG 1.0 - 1.4.1 all with the same
results)

Anyhow Darren, I don't have any redirects on connection detection like
you have in your sample and it still happens so I don't think its that
conflicting ( but I know nothing :) )

Darren McEntee

unread,
Feb 10, 2012, 12:41:03 PM2/10/12
to phon...@googlegroups.com
Any movement on this Simon, im hitting a brick wall :(

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Libby

unread,
Feb 10, 2012, 7:46:47 PM2/10/12
to phon...@googlegroups.com
What I have found with jQuery Mobile and Android (and PhoneGap 1.4.1):

jQM: HOW you get to a page can affect what the history "looks like":
<a href="" + tap  will hash something different than programmatically
going there via changePage(). Plus there's the issue of jQM's multi-page.

Using top.location may be saving history differently than say, using
top.location.assign (but I don't know much about top.location..)

To add to the mix, I've recently emerged from Android Browser Hell:
3 different devices had 3 different behaviors using jQM changePage(),
loadUrl and back button navigation. The worst being an App Error/Crash.

There's a lot brewing here, and I don't have one answer (and I don't
think there is one) but using changePage() with {changeHash: false} in
the right place allowed my app to:
* mostly do the right thing with a back button event
* NOT CRASH when it was running on the dreaded Samsung Galaxy Tab

Libby




Mike

unread,
Feb 11, 2012, 10:25:56 AM2/11/12
to phonegap
After doing much reading and searching I have fixed the issue on my
side. Basically it was a problem with how I was telling JQM to handle
the hash.

What I did first was turn off push state because that will cause JQM
to rewrite the URL or mask it so it looks better in a browser window
(something you don't need to PG) next I had to change all my
mobile.changePage() to have changeHash to true this way JQM would
update the URL and subsequently the history as well. Next on the back
button in JQM I also added an href to # this also allows for that to
go into the history etc.

Anyhow after that the app is not working as expected.

Hope this helps out.
Reply all
Reply to author
Forward
0 new messages