-1

I am trying to close my App when i press on the Back Button, all it does is just going back to Launcher Activity.

public void onBackPressed() {
    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(1);
    System.exit(0);
    finish();
}

I tried both, System.exit(1) and System.exit(0), together and each other alone. But nothing works as intended.

EDIT:

I have changed it to

        linearLayout_wrapper.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    scrollView.addView(linearLayout_wrapper);
    Log.i("Main", "initialize menu layout: complete");

}

protected void onDestroy(){
    android.os.Process.killProcess(android.os.Process.myPid());
    super.onDestroy();
}

public void onBackPressed() {
    finish();
}

And now i get an exception when i press the back button

java.lang.IllegalStateException: ScrollView can host only one direct child

Onkelbummms
  • 226
  • 2
  • 8

1 Answers1

1

finish() Launcher activity when rise this activity then you dont need write anycode onBackPresed

read this post for close app: Is quitting an application frowned upon?

Community
  • 1
  • 1
saber safavi
  • 452
  • 3
  • 8