0

I want to to exit app programmatically. How can I do this ?

I research a lot but not found any solution,Any advice or sample code please ?

I have a button in my adapter class.And when I click it, I want to close app. How can I do this ?

here is my click evet in adapter class

 public class FooterViewHolder extends ViewHolder { public FooterViewHolder(View itemView) { super(itemView); itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((MyPageActivity)mContex).finishAffinity(); } }); } } 
5
  • 1
    Have you heard of finish(); method ? Commented Mar 9, 2018 at 8:27
  • I tried but nothing happened. Commented Mar 9, 2018 at 8:28
  • I didn't understand you well but does this help: stackoverflow.com/questions/14001963/… Commented Mar 9, 2018 at 8:28
  • @podgradle type cast it with activity. ((Activity)context).finish(); Commented Mar 9, 2018 at 8:45
  • i trend but can't kill app in adapter class :( Commented Mar 9, 2018 at 9:01

1 Answer 1

9

For API >= 16, you can call finishAffinity()

For API >= 21, you can call finishAndRemoveTask()

Reference

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

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.