I'm a beginner in android, I'm practicing a Project that have a 2 labels and 1 exit button. But when I run this project in android phone the exit button is not working, it won't exit at all.
How can I make exit button work?
This question is related to
android
android-layout
layout
exit
Don't ever put an Exit button on an Android app. Let the OS decide when to kill your Activity. Learn about the Android Activity lifecycle and implement any necessary callbacks.
try this for close app
Activity.finish();
System.exit(0);
this.close_Button = (Button)this.findViewById(R.id.close);
this.close_Button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
finish()
- Call this when your activity is done and should be closed. The ActivityResult
is propagated back to whoever launched you via onActivityResult()
.
You cannot exit your application. Using android.finish()
won't exit
the application, it just kills the activity. It's used when we don't
want to see the previous activity on back button click. The
application automatically exits when you switch off the device. The
Android architecture does not support exiting the app. If you want,
you can forcefully exit the app, but that's not considered good
practice.
i try this
Button btnexit = (Button)findviewbyId(btn_exit);
btnexit.setOnClicklistenr(new onClicklister(){
@override
public void onClick(View v){
finish();
});
Source: Stackoverflow.com