如何在没有加载主要活动的情况下启动另

时间:2014-08-20 17:23:41

标签: android android-activity

我有一个活动主页是登录视图,当应用程序会话启动时,我加载另一个名为welcome user的活动。如果用户关闭应用程序,则下次用户打开应用程序时,它会直接启动欢迎活动,而不会启动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);
}

问题:如何在不加载主要活动的情况下启动另一项活动?

感谢All ...

1 个答案:

答案 0 :(得分:2)

试试这个..

  1. 在清单中将启动活动设为WelcomActivity
  2. 然后在WelcomeActivity中检查用户是否已登录
  3. 如果未登录,请启动LoginActivity
  4. WelcomeActivity.java

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // check if logged in here
        // If not logged in Start LoginActivity
    
        setContentView(layout);
    
    }
    
相关问题