Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an application with two activities and I'd like to be able to have two icons appear in the launcher, each launching the respective activity within the app.

Specifically, I want one icon to launch my main app, and another icon to launch my settings activity. Is this possible?

Here is what I've tried so far:

    <activity android:label="MyApp" android:name=".MyApp">         <intent-filter>             <action android:name=".MyApp"/>             <action android:name="android.intent.action.MAIN"/>             <category android:name="android.intent.category.LAUNCHER"/>         </intent-filter>     </activity>       <activity android:label="Settings" android:name=".Settings">         <intent-filter>             <action android:name=".Settings"/>             <action android:name="android.intent.action.MAIN"/>             <category android:name="android.intent.category.LAUNCHER"/>         </intent-filter>     </activity> 

This creates two launcher icons, but they both run my main app instead of the second icon running my settings app. I've tried just having the launcher category but then I don't get an icon so it looks like I need the main action as well.

Is this the right approach or should I be declaring two applications in the manifest instead?

like image 457
afonseca Avatar asked Jul 17 '10 05:07

afonseca


People also ask

Is it possible to have more than one launcher activity?

Yes, You can have more than one launcher activity in your application.

Can an app launch another app?

Using intents even allows your app to start an activity that is contained in a separate app. An Intent can be explicit in order to start a specific component (a specific Activity instance) or implicit in order to start any component that can handle the intended action (such as "capture a photo").

How do I get other app icons?

Go to Settings > Themes to download and apply icon packs on Samsung devices. You can download and install custom icons via Google Play Store on any Android device. You may need to install a launcher to change app icons.

How do I automatically add the App Launcher icon to the home screen when an app is installed Android?

Under the General section of the Settings menu, you will see a check box labeled "Add icon to home screen." Tap on it to tick the box. This will enable downloaded apps to be immediately shown on your home screen.


1 Answers

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.

like image 185
Rich Schuler Avatar answered Sep 17 '22 18:09

Rich Schuler