-1

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

1

3 Answers 3

0

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(); } }); } 

}

Sign up to request clarification or add additional context in comments.

1 Comment

I finish activity but it don't stop tasks in backgrund
0

you can just call finishAffinity(); in your click event

Comments

0

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.

A great example.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.