4

I have an android app where I check user credential in the first screen from a remote server. I have a timeout of 10 secs. After timeout app sends user to Error Page. There I have an Exit button.

I have tried writting all the logic for exiting the application including

android.os.Process.killProcess(android.os.Process.myPid()); 

in the click of exit button. But I am not able to ext from the application.

Please help me finding a way to exit the app.

Bhabani Shankar
  • 1,267
  • 4
  • 22
  • 41

7 Answers7

6

Why would the user want to exit the app just because the user entered the wrong credentials/dont have the right credentials?

If I were you, the error view/activity/"page" would offer a constructive solution to whatever problem brought the user there. There is not really any benefit for the user in simply saying "error" and then exiting the app.

As for your question, Google discourages implementing exit buttons. Android will "exit" your app when it sees fit and it is up to the developer to implement the correct behavior when this happens.

http://developer.android.com/guide/topics/fundamentals/activities.html

Is quitting an application frowned upon?

Community
  • 1
  • 1
fred
  • 1,812
  • 3
  • 37
  • 57
3

Call main activity's finish. Like MainActivity.this.finish()

Ron
  • 24,175
  • 8
  • 56
  • 97
  • I'd do this via a dialog explaining why you are exiting in a button onclick callback so the user knows what is going on. – steven smith Feb 18 '15 at 16:36
2

Do not try to exit the application, as that is not how android is designed to have applications work.

Instead, if you want to lock out the user (presumably to force re-authentication) destroy whatever information maintains the session - ie, refuse to do anything until they have re-authenticated. This way you control the behavior of your application using something such as credential data or a state variable that android does leave under your control, rather than something (process death) which Android somewhat uniquely removes from a developer's control.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
1
CLASSNAME.this.finish();

Where CLASSNAME is the name of the class of your active activity. Use this within the class CLASSNAME.

Pim Reijersen
  • 1,123
  • 9
  • 33
1

finish() the activity when u send user to error page and on exit press finish() that activity also....

Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
  • I have thought you way. But actually I am using an util class for http connections and for there I am sending the user to error page using context object. Is there any way I can finish the activity from where I have called this util method. I tried passing activity object to the util class and finish the same when error page is called. But it did not click. Any idea ? – Bhabani Shankar Sep 02 '11 at 12:07
  • then you should put finish() in onResume of the activity and when you close the error page , onResume of the activity will be called and there you can call finish()..you need to maintain a variable for this... – Vineet Shukla Sep 02 '11 at 12:12
1
/ add this line for Removing Force Close 
@Override
    protected void onDestroy() {
// closing Entire Application
        android.os.Process.killProcess(android.os.Process.myPid());
        super.onDestroy();
    }
}
sravan
  • 5,303
  • 1
  • 31
  • 33
1

In case the current activity is not the only one in the stack, just finish() will not exit the application. You should recursively finish() all activities in the stack to exit the application.

Dimitris Makris
  • 5,183
  • 2
  • 34
  • 54