Having more than one Launcher Activity

I'm working on an App which can read out car data. When the user opens it the first time he must choose the car he drives (this is in MainActivity). What I want to do is, that the user must not always choose his car when opening the App. The App should directly go to the car data Activity of his car after the user chose the car once. Can you please give me some ideas how to do that?

I already wrote in the AndroidManifest that MainActivity and this Car Data Activity are Launcher Activities but I think it will not work because how should the App know which Activity should be launch Activity. Please help me a bit!

You can use SharedPreference for this process.

SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(YourLaunchActivity.this);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean("isCarSet", true);
editor.apply();

Then Check Everytime Launch activity

if (sharedpreferences.getBoolean("isCarSet", false)) {
    Intent i =new Intent(YourLaunchActivity.this,SecondActivty.class);
    startActivity(i);
    finish();
    }

I will suggest you use Shared Preference.

Two launcher activities, How can I have multiple launcher activities on an Android app running on Fire TV​? (My device runs Fire OS 5.2.6.0). The setup below works on  Arguably the most popular design launchers are Nova, Apex, and Go Launcher EX. All three have been around for a few years and give you free license to rearrange your home screens, and even your app drawer. A few newcomers that are worth checking out are Dodol and Buzz Launcher. If you poke around the Internet,

So what you can do in this case is that you can use Shared Preferences. Once the data is registered in Shared Preference, every time the app is started read the data from Shared Preference and go directly to the desired page.

Sample code for Shared Preference:

Setting values in Preference:

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
 editor.putString("name", "Elena");
 editor.putInt("idName", 12);
 editor.apply();

Retrieve data from preference:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String restoredText = prefs.getString("text", null);
if (restoredText != null) {
  String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
  int idName = prefs.getInt("idName", 0); //0 is the default value.
}

more help at: https://developer.android.com/guide/topics/data/data-storage#pref

The other way around is to use sessions, but being at a nascent stage, I would suggest you to use Shared Preference.

Many launcher activities, Video shows you how to add multiple launcher icons in your Android app. If you learn Duration: 6:36 Posted: Apr 12, 2018 Because the activities in the back stack are never rearranged, if your app allows users to start a particular activity from more than one activity, a new instance of that activity is created and pushed onto the stack (rather than bringing any previous instance of the activity to the top). As such, one activity in your app might be instantiated multiple times (even from different tasks), as shown in figure 3.

You should create two activities: - MainActivity (marked as launcher activity in manifest) where you show car data. - CarChooseActivity where you choose car.

In MainAcitivity on onResume() method try to read car data (from SharedPreferences or other source). If this succeeded then show you car data, otherwise open CarChooseActivity.

Something like that:

public class MainActivity extends AppCompatActivity {

//code omitted

    @Override
    protected void onResume() {
        super.onResume();


        Car car = readCar();
        if (car == null){//no car saved
            Intent i = new Intent(this, CarChooseActivity.class);
            startActivity(i);
        }

    }

//code omitted
}


public class CarChooseActivity extends AppCompatActivity {

    Button mSaveButton;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);

        //code omitted

        mSaveButton = findViewById(R.id.savebutton);
        mSaveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveCar();//save choosed car to SharedPreferences or other storage
                finish();
            }
        });

        //code omitted
    }
}

Add Two Launcher Activities in Android Studio, How To Have Multiple Launcher Icons In One Android APK Install For Different Activities. If you've ever installed Facebook from the Google  When there is more than one app that responds to your implicit intent, the user can select which app to use and make that app the default choice for the action. The ability to select a default is helpful when performing an action for which the user probably wants to use the same app every time, such as when opening a web page (users often prefer just one web browser).

How To Have Multiple Launcher Icons In One Android APK Install , An Intent is a messaging object you can use to request an action from another app component . screen sizes · Create multiple APKs for different GL textures · Create multiple APKs with several dimensions The flags may instruct the Android system how to launch an activity (for example, which task the  Self-employed individuals often have more than one activity going at once. You can report closely related activities together on one Schedule C. If you have unrelated activities, however, you must report them on separate Schedule Cs. Similar activities would include different lines of business for a salesperson, for example.

Intents and Intent Filters, An app usually contains multiple activities . Each activity For example, an email app might have one activity to show a list of new… Defining launch modes; Handling affinities; Clearing the back stack; Starting a task. More  It is possible to keep more than one launcher in your Android device at a time, such that you can switch between them. Tho different lunchers comes with different functions or settings, making it user dependent or you can say how a user wants to keep those settings. That's the only use of having two or more luncher.

Understand Tasks and Back Stack, Hence, there is often a need to deal with multiple activities. For example, a This activity can launch another activity, usually after a trigger event. This causes  This code should be placed in your AndroidManifest.xml file, and it declares that a Java class named MyMainActivity is the launcher activity for your Android application. (I assume that you already know about that file and just needed to see this syntax, so I won’t explain any more about this here.)

Comments
  • your app must have only one launcher activity. What you can do is saving the chosen car in the app's shared preferences. when the main activity starts, you check in the prefs. If there is a saved car, you automatically start the second activity, else you ask which car the user wants to chose
  • You need to use the Sharepreference for it.And than after on above the setCOntentVew method u need to use the intent on your luncher activity