本文介紹了安卓閃屏定時器插件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我是開發Android應用的新手,我正在嘗試檢查會話是否登錄,如果用戶登錄,它應該不會顯示閃屏,但如果用戶沒有登錄,它應該會顯示3秒的閃屏。
但是閃屏一直在顯示,所以我想我在if/Else這件事上做錯了,希望有人能幫助我:)
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);
}
}
}
推薦答案
我自己修復的代碼如下:
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);
}
}
}
這篇關于安卓閃屏定時器插件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,