5

In my program I have an activity that gets launched when the application opens. If I open a couple more activities, how can I go back to the main activity? In the intent filter, the name of the activity is "android.intent.action.MAIN", and it will not allow me to call startActivity() on it. What do I do?

user1332680
  • 51
  • 1
  • 1
  • 2
  • 1
    don't think you can just call startActivity with a activity from another application. I think your only bet is implicit intent. – CChi Apr 14 '12 at 00:31

1 Answers1

4
Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

Let's say your activity stack is as follows... MainActivity > Activity1 > Activity2> Activity3, Running the code above will close activities 1 & 2 and resume MainActivity

Mark Pazon
  • 6,167
  • 2
  • 34
  • 50