0

I am a newbie with programming Apps. Before asking this question I read several topics on StackOverflow but I can't find a solution.

My App has a Main Activity that immediately calls a "Second Activity" (I am trying a workaround for another problem I have) that would be the real "first page" (a Main Menu) of my application. So, here I set an Alert Dialog on my phone "Back Button" pressed asking "Are you sure you want to exit App?".

Now, I tried different solutions. One takes me to the Main Activity (a simple blank page), and ...

android.os.Process.killProcess(android.os.Process.myPid());

Will restart (I Think) my app, because after a few moments, I can see a blank page and again my "Second Activity" (Main Menu) as if It was called from Main Activity.

Is there a way to stop my APP without showing my hidden MainActivity or auto-restarting my App? Thanks! :)

Funesto
  • 67
  • 1
  • 9

1 Answers1

4

When you add this code the first activity .It will finish the previous.

Intent main= new Intent(MainActivity.this,SecondActivity.class);
startActivity(main);
MainActivity.this.finish();

Happy Coding :)

6155031
  • 4,171
  • 6
  • 27
  • 56