views:

153

answers:

1

Hi,

I want to show a simple toast, when exiting an application. The problem is, that the toast is not shown. I assume it is because the acitivity is finished or because of System.exit(0), but I don't know how to solve it. Does anyone have a tip? Thanks!!

In my activity I have the following code:

Toast.makeText(this,"Exit application.",Toast.LENGTH_SHORT).show();
exitApp();

public void exitApp (){
  App.getInstance().exit();
  finish();
}

And the mehod exit in App:

public void exit() {
   System.exit(0);
}
+1  A: 

It is advisable that you call finish to close your application rather than calling System.exit(0); since this approach will kill your application completely.System.exit() kills your entire process. finish() just hides, stops and destroys your activity. Your process is still running.

You can just use finish(); to close your activity and this should solve your problem.

http://groups.google.com/group/android-developers/browse_thread/thread/63de8a9cdffa46a3?pli=1

Rahul
Sorry, I didn't describe it correct: App extends the Application class and is therefor not an Activity.
Sebastian Büttner
the Q is how to show toast, any idea?
Ankit Jain
Yes but it is not extending it to an activity. I think the context should be passed from the activity class to his class extending application so that he can show the Toast there.
Rahul