[英]How start another activity without load main activity?
我有一個活動主體,它是一個登錄視圖,當應用程序會話啟動時,我會加載另一個名為“歡迎用戶”的活動。 如果用戶關閉了應用程序,則下次用戶打開該應用程序時,它將直接啟動Welcome活動,而無需啟動在文件AndroidManifest.xml中配置的主要登錄活動。
注意:當應用啟動時,我在空白處打開主要活動,然后在另一個活動中使用以下代碼:
// Activity Main
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sessionPreferences = new SessionPreferences(getApplicationContext());
//verify if user had session initiated
if(sessionPreferences.getSession())
{
startHome();
}
else
{
setContentView(R.layout.login);
etUsername = ((EditText) findViewById(R.id.txtUsername));
etPassword = ((EditText) findViewById(R.id.txtPassword));
chkRememberMe = (CheckBox) findViewById(R.id.chkRememberMe);
Button btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(this);
etPassword.setOnEditorActionListener(this);
rememberMe();
}
}
private void startHome()
{
Intent welcome = new Intent("com.login.login.welcome");
welcome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(welcome);
}
問題:如何在不加載主要活動的情況下開始另一個活動?
感謝所有人...
嘗試這個..
WelcomeActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// check if logged in here
// If not logged in Start LoginActivity
setContentView(layout);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.