javaandroid-studiomain-activity

How to connect two activities to make a program?


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,


Solution

  • 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();.