0

I am a beginner in java. I want to make sure to link my second main activity on my first activity. I try to put a line of code in my first activity but that does not connect anything at all. I put the line of code:

Intent intent = new Intent(this, DeuxiemeActivity.class);
            startActivity(intent);
            finish();

Thanks,

Enitoup
  • 3
  • 1
  • Why are you calling finish() after starting the second activity? You will be unable to return to your first activity in that way, unless that's what you want for some reasons. What exactly is the error you get while trying to start the second activity? – lidkxx Jun 07 '17 at 14:03

1 Answers1

1

Inside AndroidManifest.xml,

Change

<activity android:name=".MainActivity">

to this,

<activity android:name=".MainActivity" android:noHistory="true">

noHistory="true" and finish() both are similar.

But, When we start a new activity, It will be closed at the same time. So using noHistory="true" is better than using finish();.

Yash Amin
  • 106
  • 1
  • 7