Page 1 of 2

How can i override the back key to return to last application and not exit?

Posted: Sun May 06, 2012 11:13 pm
by mikeflores2000

I'm running Android 4.0 and my app results in hot links displayed in the output.
Clicking a hot link sends me to another page but clicking the back key totally exits application.
How can I intercept or handle the Android back key to return back to my Tiggzi application?
Backbutton event handler in Tiggzi IDE appears not to fire. What did I miss?
Last Active Activity involves package
com.tiggzi.project32447 which should spell out
public class MyTiggziActivity extends Activity {
...
}

At a lower level, I found some code from the SDK that may help:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK) {
//do what you want
return true;
}
return super.onKeyDown(keyCode, event);
}


How can i override the back key to return to last application and not exit?

Posted: Mon May 07, 2012 4:05 am
by maxkatz

The Backbutton event is from PhoneGap. Can you post the code you are running on the Backbutton event? Are you testing it via Tiggzi tester or installed the app on the phone?


How can i override the back key to return to last application and not exit?

Posted: Tue May 08, 2012 8:54 pm
by mikeflores2000

Works fine via Tiggzi tester on MacBook Pro Safari browser.
Testing app on Android device.

I'm looking at com.phonegap.plugins.childBrowser package in class ChildBrowser:

  • Checks to see if it is possible to go back one page in history, then does so.
    */
    private void goBack() {
    if (this.webview.canGoBack()) {
    this.webview.goBack();
    }
    }

    *** However the phone gap documentation is different ***
    http://docs.phonegap.com/en/1.7.0/cor...

    Full Example

    <!DOCTYPE html SYSTEM

    Cordova Back Button Example


How can i override the back key to return to last application and not exit?

Posted: Tue May 08, 2012 9:34 pm
by maxkatz

How do you test the back button in the browser..?

Tiggzi currently uses PhoneGap version 1.5.


How can i override the back key to return to last application and not exit?

Posted: Tue May 08, 2012 10:01 pm
by mikeflores2000

Actually I noticed the back button is greyed out in Safari and Firefox.
A new tab is opened so exiting it allows for return to app.


How can i override the back key to return to last application and not exit?

Posted: Tue May 08, 2012 11:15 pm
by mikeflores2000

I'm not sure if this behavior of exiting totally out upon tapping back key
is a bug and similar to another bug fixed by Phonegap 1.6:

http://phonegap.com/2012/04/11/phoneg...

Android
[CB-367] Back button event should fire on key up not key down
Also changed menu key and search key to be consistent.


How can i override the back key to return to last application and not exit?

Posted: Wed May 09, 2012 3:21 am
by maxkatz

The back button that you are trying to overwrite is the physical button on Android devices, not the browser back button. You should only test it on the actual device.


How can i override the back key to return to last application and not exit?

Posted: Wed May 09, 2012 4:43 am
by mikeflores2000

Affirmative:
https://issues.apache.org/jira/browse...

fixed in Phonegap 1.7.0 ( Apache Cordova )

https://issues.apache.org/jira/browse...
fixed in Phonegap 1.6.1 ( Apache Cordova )
Impacts Samsung Focus.

Bug reproduced on Samsung Galaxy Nexus running ICS ( Android 4.0.2 )


How can i override the back key to return to last application and not exit?

Posted: Wed May 09, 2012 10:41 pm
by mikeflores2000

Any plans by Tiggzi to upgrade to Phonegap 1.7 where issues are resolved?


How can i override the back key to return to last application and not exit?

Posted: Wed May 09, 2012 11:40 pm
by maxkatz

Yes, just no date yet (very busy with other things). You can always export the app source, and update PhoneGap manually.