Bhabani Shankar
Bhabani Shankar

Reputation: 1285

Exit an Android app

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.

Upvotes: 4

Views: 3618

Answers (7)

Ron
Ron

Reputation: 24233

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

Upvotes: 3

Chris Stratton
Chris Stratton

Reputation: 40337

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.

Upvotes: 2

fred
fred

Reputation: 1822

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?

Upvotes: 6

Dimitris Makris
Dimitris Makris

Reputation: 5183

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.

Upvotes: 1

sravan
sravan

Reputation: 5333

/ add this line for Removing Force Close 
@Override
    protected void onDestroy() {
// closing Entire Application
        android.os.Process.killProcess(android.os.Process.myPid());
        super.onDestroy();
    }
}

Upvotes: 1

Vineet Shukla
Vineet Shukla

Reputation: 24021

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

Upvotes: 1

Pim Reijersen
Pim Reijersen

Reputation: 1133

CLASSNAME.this.finish();

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

Upvotes: 1

Related Questions