I am new into developing android app, and I am trying to check if session is logged in, If the user is loggedin, It should not show the splash screen, but it the user is not loggedin, it should show the splash screen for 3 seconds. (Using code from http://web.archive.org/web/20130712051340/http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/)
But the Splash screen is showing all the time, so I think I done it wrong with the If/Else thing, hope someone can help me with that ๐
JavaScript
โx
public class SplashScreen extends Activity {
โ
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
private SessionManager session;
โ
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
โ
// Session manager
session = new SessionManager(getApplicationContext());
โ
// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
new Handler().postDelayed(new Runnable() {
โ
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
โ
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app login activity
Intent i = new Intent(SplashScreen.this, LoginActivity.class);
startActivity(i);
โ
// close this activity
finish();
}
}, SPLASH_TIME_OUT); } else {
setContentView(R.layout.splash_screen);
}
โ
}
}
โ
Advertisement
Answer
I Fixed it my self this this code here:
JavaScript
public class SplashScreen extends Activity {
โ
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
private SessionManager session;
โ
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
โ
// Session manager
session = new SessionManager(getApplicationContext());
โ
// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
โ
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
โ
// close this activity
finish();
โ
} else {
โ
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable() {
โ
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
โ
@Override
public void run() {
โ
Intent i = new Intent(SplashScreen.this, LoginActivity.class);
startActivity(i);
โ
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
}
โ