Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Skip the first activity under a condition

Tags:

android

I'm building a group of apps as a package similar to MS Office. Here each app has its own launcher as well as it can be launched from inside the home app. Each app has a login page. I need to display the login page when the app is launched from android launcher and not showing login page while launch from home app, How can i achieve this?

My scenario:

From Launcher----->(App)Login page--->(App)Home screen

From Home app----->(App)Home screen

like image 858
Manoj Kumar Avatar asked Dec 11 '22 21:12

Manoj Kumar


2 Answers

You can do that by launching an empty activity (with no UI) and in its OnCreate method depending on some variable information (You can use SharedPreferences perhaps for that purpose) you can decide which Activity to start (Login or Home Screen app).

PS:

Btw if the login always leads to the same activity (Home Screen and is not used to login somewhere else) you don't even need the empty activity, you can check this in the Oncreate method of the login activity

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

    if (logged_in_check_is_true)
       { 
          Intent intent = new Intent(this, HomeScreenActivity.class);
          this.startActivity (intent);
          this.finishActivity (0);
       }

    ...
like image 151
tozka Avatar answered Jan 11 '23 00:01

tozka


You should always start LoginPageActivity. But if you start it from your "home app" just pass special extra to activtiy:

public class LoginPageActivity extends Activity {
    onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        boolean needLogin = getIntent().getBooleanExtra("need login extra", true);
        if (!needLogin)
        { 
            // start your home screen
        }
        //setup login page
    }
}

In home app just pass "need login extra" as false.

like image 38
Jin35 Avatar answered Jan 10 '23 23:01

Jin35