how to display alert message when some one clicks on back button

by manoj » Tue, 27 Jan 2009 21:12:01 GMT


Sponsored Links
 Hi friends,

I want to display an alert asking "do you want to exit from the
application yes/no?" before exiting the application (when we click the
Back button).

Can any one please help me how to achieve this?

Thanks,
Manoj.
--~--~---------~--~----~------------~-------~--~----~



how to display alert message when some one clicks on back button

by Mark Murphy » Tue, 27 Jan 2009 21:12:33 GMT


 


Probably you will want to use AlertDialog, perhaps created using the
AlertDialog.Builder class.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


how to display alert message when some one clicks on back button

by manoj » Tue, 27 Jan 2009 21:17:54 GMT


 can you please show me the sample code?





--~--~---------~--~----~------------~-------~--~----~



how to display alert message when some one clicks on back button

by Tommaso » Wed, 11 Mar 2009 16:27:47 GMT


 Mark,

that works for Alerts if you have only ONE activity in your app.
For example purpose it is great. For real life it is misguiding.

I couldn't find a solution yet.
How do you show AlertDialog from a subactivity!?

Ciao,
  Tommaso





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Passing data from intent caller to intent receiver?

Having used a dozen GUI toolkits (from Xt to Qt, Java Awt/Swt/Swing,
Qtopia, etc) I really find it difficult to get used to Android. I
guess there should be a Java GUI (or traditional Desktop GUI) to
Android GUI transition guide :)

Suppose I have the MainView Activity class which explicitly calls
DetailedView via intent mechanism as shown next: (Is there another way
to call DetailedView?)

-Since an Activity class is instantiated via onCreate() how do I
customize it? (No constructor, only pass data through intent!)

-Is there a way to get a reference for the DetailedView instance in
MainActivity?

-Is there a way to get a reference for the MainActivity instance in
DetailedView?

-How can I pass the reference to FrontEnd to the DetailedView class?
Intent.putExtras() allows only for certain data types to pass to the
intent receiver class.

----------------------------
MainActivity code ...

...
FrontEnd fe;

...
public void onCreate(Bundle savedInstanceState) {
...
Intent myIntent = new Intent(this, DetailedView.class);
...}

protected void onListItemClick(ListView l, View v, int position, long
id) {
...
    startActivityForResult(myIntent,..);
...
}

--~--~---------~--~----~------------~-------~--~----~

2. Duplicate processes triggered from ongoing notification

I added a notification for an ongoing process, however when this is clicked
on it triggers a duplicate process and when you exit the duplicated process
the original copy is re-run by the operating system.

The app I'm working on doesn't use the main activity window, except to
trigger one of 2 other activities and this might be part of the problem
since I noticed the same issue in other applications like AndNav2.

My question is, how do I work round the issue to bring the running activity
to the front, rather than triggering a new activity, killing the first and
then the OS re-runs the first activity when the new one is quit?

--~--~---------~--~----~------------~-------~--~----~

3. fullscreen doesn't hide Status Bar in Android SDK 1.5 R2

4. contentobserber for my database

5. Socket timeout not working?

6. Localice Android applications and base system

7. Blogging Tool