Question

When I install my application onto a device or emulator it appears multiple times in the apps menu, in my case I get 4 icons showing my application name.

It seems that each icon is representing an activity, and since my application contains 3 tabs(with activities) the first 3 icons on my menu go to a particular activity, and the 4th icon takes me to the app itself

This is my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.jameselsey"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-sdk android:minSdkVersion="7" />  
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>    
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

    <application    android:icon="@drawable/icon" 
                    android:label="@string/app_name" 
                    android:name="com.jameselsey.domain.GlobalState"
                    android:theme="@android:style/Theme.NoTitleBar">

        <activity android:name=".DefaultActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

         <activity android:name=".MyContactsActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

         <activity android:name=".MyMapsActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>   

        <activity android:name=".OptionsActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <uses-library android:name="com.google.android.maps" />
    </application>    
</manifest> 

What can I do to only have one icon for my app on my device and not 4?

Thanks

Was it helpful?

Solution

The answer has already been provided but i am just briefing it. In Java the application will start with the class which contains the main method and that will basically be a single entry point to the entire application.

In Android you could have noticed that there is no main method inside your Activity class. Here we use Manifest file to do the same. An application can have multiple entry points and "android.intent.action.MAIN" indicates that this activity should be the main starting activity and the LAUNCHER category says that this entry point should be listed in the application launcher. Once you make an activity as LAUNCHER android provides an application icon and name to it and you must have noticed that clicking on each of the 4 icons in your case would take you to 4 different activities.

The bottom line is if our application doesn't require multiple entry points you don't have to use it.

OTHER TIPS

Because you have 4 activities with

`            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

That adds a launcher icon for your activity.

remove intent-filter from the last 3 activities

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top