• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to implement Back button functionality

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

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

Thanks
Srini
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you exactly mean by "implementing back button functionality"?

Android phones have a back button clicking on which takes you the previous activity.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 28701
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
bob thebob
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic