How I have app where I have 2 activities and on second I have quit button which passes me to first activity. What should I do if I would like to kill all process after click this button? I mean that I will back to my previously activity with stop all tasks in background
3 Answers
Button button = (Button) findViewById(R.id.btn1); button.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) { activity.finish(); // to move out of activity // to move out of the app //activity.finishAffinity(); } }); } }
1 Comment
Is the correct scenario to close the app by a button / by user action?
You should have a really well scenario to use this case.
Is against application processing principles.
Android framework only kills applications only if the resources are needed. Also has extra benefits: App startup is faster if the process is alive.
Activity.finish(); // will finish the current activity. Activity.finishAffinity() //removes Activitys belonging to a specific application from the current task If it's the case you want to "exit" the application I would recommend an approach where you "simulate" closing the application. (you bring the HomePage in front)
Intent homePageIntent= new Intent(Intent.ACTION_MAIN); homePageIntent.addCategory( Intent.CATEGORY_HOME ); homePageIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(homePageIntent); Oh another tip: Before asking a question try to search your question on Google. You could have noticed that your question was asked multiple times.