implement BACK Button

edited November 2013 in Android Mode

I know it has been talked years ago, because I found posts about it, but I've been trying to override the back button implementation as explained in the Wiki, and keyCode = 0; doesn't seem to work.

My intention is to add some Ctrl+Z functionality in my app until I reach the main screen. That's why I want to override it.

I've read that joshgiesbrecht pulled a request to solve this by overriding the onBackPressed() function, and it was merged. However I don't know if my Android Mode version is updated with that changes, how could I update to it, or how to use it.

https://github.com/processing/processing-android/pull/52

Answers

  • Disclaimer: I have been involved in a lot of Android-specific design practice lately.

    This is the wrong approach. You should never change the back button's functionality to behave in any way other than to move "up" a chain of Views. To use it as an undo button, in what could easily become a very large chain of edits, would be tiresome for the user seeking to exit the app. Instead, you should create a dedicated "undo" button within the app (in the Action Bar in a native app, but this obviously isn't an option here...).

    For the sake of the argument, it should be possible to implement what you describe, even if it is fundamentally wrong from a design standpoint. There are situations where overriding the functionality of the back button is acceptable and, in fact, expected. In my experience, the keyCode = 0 method only worked when the app was signed for distribution. This isn't easy to work with for development, and may not even be the case anymore. I agree that an alternate solution should be found. At this point, however, I'm not sure that there is one (having just tested out several of my ideas)...

  • edited November 2013

    That sounds reasonable because if you oblige someone to "close" your app with HOME the button, it stays in background with onStop() state, and doesn't kill itself until a long time or maybe never.

    I'll think about the "undo" button, however it is a pitty because it is a drawing tool and it would be better to not interfere with buttons on the canvas, or opening the menu to select the undo feature.

    Is there any way to make the app kill itself after some time spent in onStop() state? The build-in browser from Samsung I have, uses the "Back" key to go back a page :/

  • Still, the concept of going back a page is fundamentally different from the concept of going back a step in an undo history. In the browser, pressing the back button visibly shifts the current view to one that was displayed before, with entirely new content (and an animation). Undoing a single step within a single view is different... and this is not how Android is meant to behave. It's hard to explain...

    Is there any way to make the app kill itself after some time spent in onStop() state? The build-in browser from Samsung I have, uses the "Back" key to go back a page :-/

    I'm not entirely sure what you mean here. Android's system will automatically kill older apps when it needs to free some memory.

Sign In or Register to comment.