It's not a secret anymore!
The moose likes Android and the fly likes How to implement Back button functionality Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "How to implement Back button functionality" Watch "How to implement Back button functionality" New topic
Author

How to implement Back button functionality

Sreenu Vengala
Greenhorn

Joined: Oct 26, 2009
Posts: 18
Hi.

Any one help on how to implement Back button functionality in Android phone.

Thanks
Srini
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1365

What do you exactly mean by "implementing back button functionality"?

Android phones have a back button clicking on which takes you the previous activity.


[List of FAQs] | [Android FAQ] | [My Blog] | [Samuh Varta]
Fadwa Belghith
Greenhorn

Joined: Dec 30, 2009
Posts: 1
Hi,

I want to implement a back button wich appears on the top layers of all screens menu.

In fact, i don't have a keyboard and i want to create a button wich works like a real back button.

How can i proceede ?

Thank you very much
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14572
    
    7

If you went and overlaid a big ugly GUI button over the top of the app I wrote, I think I'd be rather annoyed. For one thing, it wouldn't have any idea of what part of the display was "safe" to write over and what part was attached to critical program functionality.

As Moni has pointed out, there's a physical pushbutton on Android phones that's reserver for the "back" function. It has a default operation, but individual parts of individual apps sometimes remap this function to be more appropriate to the needs of that particular app.

I'd recommend actually installing the Android developer's kit and working with the phone simulator if you don't have access to a physical Android phone. That way you can begin to develop a feel for the particular way in which Android phones operate.


Customer surveys are for companies who didn't pay proper attention to begin with.
Vikram Ara
Greenhorn

Joined: Jan 15, 2010
Posts: 1
I would also like to implement this Back as a button in my screen. Its more like giving an intuitive feel for the user.... like Gmail where they have go 'Back to Inbox' . Any help ?
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1365

As regards Back button, there are few things to consider here(as was pointed out by Tim):
Every Android phone (till date) has a physical back button on the handset. Default behavior of this button is to stop the current activity that is displaying on the screen. You can override the default back button functionality to whatever you want.Read this to understand how to do that.

Alternatively, you can provide a soft button on your screens(like what Iphone applications have). You can attach a click listener to this button and override the onClickListener to do whatever you want( i.e. start new Activity, finish the current etc.)

How to implement the functionality?

The key to implementing "Back" functionality is understanding how to manage Activity's History Stack and also defining what "Back" would actually mean for you application(would it take the user to the previous screen in the application flow? Or would it take the user to the last screen visited?). To get an understanding of how activity stack is organized you need to understand the concept of Activities and Task.
bob thebob
Greenhorn

Joined: Sep 06, 2010
Posts: 2
I also would like to be able to do this.

Specifically I would like to create an app that runs in the background that provides the *exact same* functionality as the hard coded 'Back' button.

the reason? I have a Droid X, and it is BIG. it makes it extremely hard to use one-handed and having a swipe gesture function as a back button (like in Palm Pre for example) would *greatly* increase the ease of use.

so you see, I don't want to put a big honking button on top of your app. I just want to be able to use my phone one-handed.

as far as I'm concerned the app could just be one simple class that contains:
1) a listener for your 'back' swipe
2) a call to the physical hard button itself

is this possible? are there built in APIs for the hard coded buttons that would allow me to call them without actually pressing them?

again - I'm not interested in overriding the button, I'm interested in making a software call to it - or failing that, in emulating it's behavior in any and all states, apps and situations.

cheers,
b
Lautaro Brasseur
Greenhorn

Joined: Aug 06, 2005
Posts: 13
I think that you can just call the finish() method on the activity. This will pop it from the stack and will back to the previous one.

Lautaro Brasseur<br />SCJP 1.4 (95%) / SCBCD 1.3 (100%)
bob thebob
Greenhorn

Joined: Sep 06, 2010
Posts: 2
thanks Lautaro,

to clarify tho - I'm looking for a background app that can call finish() on whatever the front app is at the moment...

example, a user downloads and installs my app, sets it to launch at startup, and sets prefs etc.
then during a day of normal use:

1. user is at Home screen
2. user selects launches K-9 Mail program (for example)
3. Mail app takes user to Inbox
4. user opens message
5. user decides to return to inbox

6. user makes screen gesture.
6a. screen gesture is intercepted by my app
6b. my app sends message to Mail app
7. Mail app returns to Inbox

8. user makes screen gesture
8a. screen gesture is intercepted by my app
8b. my app sends message to ? Android System ?
9. user is taken back to Home screen

in other words the 'back' button functionality works exactly like the button - within apps, across apps, in the system, etc etc

whaddya think?

b

Tim Kaiser
Greenhorn

Joined: Sep 09, 2010
Posts: 2
hi,

The back button on the phone is just finishing the current activity causing previous activity on the activity stack to start again.

If you put the following code in a button click listener, you will get the same functionality as back button does:



back button does not do anything fancier than this.
Ron Reibling
Greenhorn

Joined: Sep 17, 2010
Posts: 1
Another reason to be able to use the swipe gesture for a "back" key is many of the Sprint Epics "back" hard key doesn't work very well. Much like LauncherPro allows you to set a swipe gesture to all the icons on the dock, it would be nice to be able to have an icon that when you swipe it, does exactly what the "back" hard key does.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to implement Back button functionality
 
Similar Threads
button to new page
browser back button functanality
Implementing back functionality
Doubt using JButton
Pattern question about caching