0

I am working on app has 3 activitys , I want to close the app totally when I click on button in Main Actvity.

I have used finishAffinity(); System.exit(0);

// and finish();

closeBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

                   finishAffinity();
                    System.exit(0);

               //     finish();
        }
    });

I want to close the app (all activitys), but the app just minimized and still working.

  • 2
    Possible duplicate of [How to quit android application programmatically](https://stackoverflow.com/questions/6330200/how-to-quit-android-application-programmatically) – Bö macht Blau Feb 01 '19 at 19:52

1 Answers1

0

Using onBackPressed() method:

@Override
public void onBackPressed() {    
    android.os.Process.killProcess(android.os.Process.myPid());
}

You need not to just kill the activity but the app's process

Rainmaker
  • 10,294
  • 9
  • 54
  • 89
  • I tried this method, but it dose not work, same ,the app just will be minimized – Omar Thamer Feb 01 '19 at 20:20
  • app is not minimized it is in recents, if you click on it, then it will run from the landing activity. If you need to also remove it from recents, you can refer https://stackoverflow.com/questions/13385289/remove-app-from-recent-apps-programmatically – Rainmaker Feb 01 '19 at 21:23
  • thanks bro, I found useful code at the link that you provide – Omar Thamer Feb 02 '19 at 14:49