Reputation: 11
I want to run the activities like Splash screen then intro slider & then main activity. But it runs the splash screen but doesn't run the intro slider after flash screen. How to fix this?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.introslider">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="info.androidhive.introslider.Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="info.androidhive.introslider.WelcomeActivity" />
<activity
android:name="info.androidhive.introslider.MainActivity"
android:label="@string/title_activity_welcome"
android:theme="@style/AppTheme.NoActionBar"/>
</application>
</manifest>
Splash screen.java
package info.androidhive.introslider;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Splashscreen extends Activity {
private static int SPLASH_TIMER = 1000;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(Splashscreen.this,MainActivity.class);
startActivity(i);
finish();
}
},SPLASH_TIMER);
}
}
Upvotes: 1
Views: 1014
Reputation: 2161
SplashScreen.java this is you first file
public class Splashscreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Intent intent = new Intent(this, WelcomeActivity.class);
startActivity(intent);
finish();
}
}, 5000);
}
}
WelcomeActivity.java
public class WelcomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
Button btn =findViewById(R.id.welcome_botton);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
});
}
}
WelcomeActivity.xml
<Button
android:id="@+id/welcome_botton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" />
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
// YOUR MAIN ACTIVITY LOGIC WRITE HERE
}
}
Refer this Hierarchy and Register all activities in Manifest.xml
file
these all activity created by me for your reference.
Upvotes: 2
Reputation: 1543
Start the WelcomeActivity from SplashScreen.
public class Splashscreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
startActivity(new Intent(this, WelcomeActivity.class));
finish();
}
}
Then in your Intro slider activity use sharedpreference to check for first launch. After the first launch your app will move from splash screen to MainActivity.
Upvotes: 1