-1

I created an app where I put two principal activities. This is the code I added in the Manifest:

<activity android:name=".MainActivity">
        </activity>
    <activity android:name=".Menu">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

To quit, i connected two methods to two buttons, one in the first activity and one in the second.

    public void Quit1(View v){
    finish();
    System.exit(0);
}
public void Quit2(View v){
    finish();
    System.exit(0);
}

If i click the first button(connected with Quit1), the app closes(that's what I wanted) but when i press the second one(connected with Quit2), I return at the first activity. How can I quit also in the second activity?

P.Halley
  • 54
  • 7

2 Answers2

0

Donot use System.exit(0)

What it does is , it only finishes the current activity, if you have any other activity in the stack, that activity will be started. For example, you have 2 activities A and B. You move from activity A to B, and use System.exit(0) there it will finishes the activity B and restarts the app with activity A. Same in your case.

Simple use.

YourActivity.finish();
Abdul Kawee
  • 2,687
  • 1
  • 14
  • 26
-1

try this to go back to home screen without respective to any background avcitvity

  Intent startMain = new Intent(Intent.ACTION_MAIN);
  startMain.addCategory(Intent.CATEGORY_HOME);
  startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(startMain);
Mohammad nabil
  • 1,010
  • 2
  • 12
  • 23