How to Get Multiple Icons to Launch Different Activities in One Application

How do I get multiple icons to launch different activities in one application?

What you need to do is have your settings activity launch in another task. You can do this by specifying its task affinity. This is done with the attribute android:taskAffinity. By default all activities share the same task affinity that defaults to main package specified in the manifest. On your settings activity you can specify android:taskAffinity="your.own.package.SettingsTask" to have the settings activity launch in its own task.

Extra documentation.

How to open main activity from two separate icons with different ui

First you need to add second launcher intent to your manifest.

        <activity
android:name=".yourpackage.MapActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<meta-data android:name="visibility" android:value="0"/>
</activity>

<activity-alias
android:name=".MapWithoutFabActivity"
android:targetActivity=".yourpackage.MapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<meta-data android:name="visibility" android:value="1"/>
</activity-alias>

Next we need modify our map MapActivity for being ready to change visibility of fab button.

public class MapActivity extends AppCompatActivity {

protected int fabVisibility = View.VISIBLE;

@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Hope this method works.
Bundle bundle = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA).metaData;
int visibility = Integer.valueOf(bundle.getString("visibility"));
fab.setVisibility(visibility);
}

protected void onNewIntent(Intent intent) {
Bundle bundle = getPackageManager().getApplicationInfo(getPackageName(),
PackageManager.GET_META_DATA).metaData;
int visibility = Integer.valueOf(bundle.getString("visibility"));
fab.setVisibility(visibility);
}

Good luck there

Emre

How to assign visually different launch icons for different Android activities

In each activity element of your manifest add the android:icon attribute and assign it to a drawable. For example <activity ... android:icon="@drawable/icon_x".

Two launcher activities

You need to specify which activity is the default one by adding the following line to your intent-filter:

<category android:name="android.intent.category.DEFAULT"/>

Insert this in the default activity and keep the rest. Then it should work.

You may also want to add a different icon to your 2nd activity with the attribute android:icon="@drawable/myothericon"

Android App activities installed as multiple icons

Your manifest file should only have this line in the activity you want to have an icon:

<category android:name="android.intent.category.MAIN" />

Based on your description, it sounds like both activities have this line.

Android application suite with multiple launcher icons does resumes to same activity no matter which was selected

You'll have to set the activities with different task affinities. See the Application Fundamentals section from the Android docs.



Related Topics



Leave a reply



Submit