我正在構建一個包含許多幻燈片的Intro頁面的應用程序。一旦第一次使用者經歷了介紹,他將被引導到登錄屏幕。一旦他登錄(或註冊),他將被帶入應用程序主頁。只要用戶沒有註銷,如果他點擊應用程序圖標,他就會直接進入主屏幕。從單一意圖指向不同的意圖(最佳做法是什麼?)
我使用Intro頁面意圖作爲LAUNCHER活動,並使用sharedpreference
來保存'首次使用'和登錄狀態。通過測試用戶是否已經登錄或第一次用戶,我正在引導他到不同的意圖。
所以我的問題是,哪裏是最適合做這種意圖重定向的位置?因爲Intro頁面有這麼多的片段和組件,將它設置爲LAUNCHER活動並在那裏有所有if else語句來決定用戶應該去哪裏,我浪費了系統資源嗎?因爲如果用戶已經登錄,他將進入主頁而不顯示任何已加載的應用程序介紹內容。
或者創建一個空活動並將其設置爲LAUNCHER活動並將所有if else語句放在該活動中是一種很好的做法。因此,該應用不需要轉到「重」應用介紹頁面。 PS:我已經在super.onCreate()之後的onCreate語句中聲明瞭那些intent direction if else語句。
@Override
protected void onCreate(Bundle savedInstanceState) {
// Fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
// activity_first_usage is the container for all frames
setContentView(R.layout.activity_first_usage);
logger = new Logger(this);
if (!logger.isFirstUsage()) {
if (logger.hasTOKEN()) {
// If user didn't log out, then he can stay in the app
Intent home = new Intent(getApplicationContext(), Home.class);
startActivity(home);
finish();
} else {
// If this is not the first time user login in, no need to show the intro
Intent directToSignIn = new Intent(getApplicationContext(), SignIn.class);
startActivity(directToSignIn);
finish();
}
} else {
// If not, continue with the Intro and set usage status to used
logger.setFirstUsage(false);
}
...
}