0

I have an activity main that is a login view, when app session starts , I load another activity named welcome user. if the user closed app, the next time that user opens the app, it starts the welcome activity directly without launching the main login activity configured in the file AndroidManifest.xml .

NOTE: when the app starts , I open the main activity in blank and later another activity, I am using this code :

     // 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);
}

QUESTION: How start another activity without loading main activity?

Thank to All ...

Tommie C.
  • 12,895
  • 5
  • 82
  • 100
  • 1
    You should change the launch activity to your welcome one, then test if a user is logged in or not. Android will always launch the activity stated in the manifest, however you can have multiple launch activities. http://stackoverflow.com/questions/3631982/change-applications-starting-activity-android – Jesson Atherton Aug 20 '14 at 18:04
  • Thank you, one possible solution is change default activity in the Debug configuration, but for example if I choose welcomeActivity , I have validate session, if the user is not online , every time that the user starts app will load welcomeActivity and anyway show the activity in blank and later will execute intent, I don't want do that – Android Developer Aug 20 '14 at 22:34

1 Answers1

2

Try this..

  1. In manifest make the start activity as WelcomActivity
  2. Then in WelcomeActivity check if the user logged in
  3. If not logged in,then Start the LoginActivity

WelcomeActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // check if logged in here
    // If not logged in Start LoginActivity

    setContentView(layout);

}
Sabeer
  • 3,940
  • 1
  • 24
  • 20