natsuVsnaruto natsuVsnaruto - 1 month ago 12
Android Question

How to start another activity after a splash screen in android studio

Hi everyone I'm studying now and developing a app in android studio. My problem is i can't proceed to my log in activity after splash screen. I already look in the net and stackoverflow and applied it, but still same error. I appreciate for the help and answer.

Here are some of my code

SplashScreen.java

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
final Intent mainIntent = new Intent(SplashScreen.this, Login.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
}
},3000);

}


Login.java

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);

Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
}


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>




<application
android:allowBackup="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".Login"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Login"/>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="com.ex.app.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>




where did i go wrong ?

Answer

As you have written code to move to MainActivity on the method onCreate of Login.java

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

Comment this line or keep it on the click of SignIn button