3

I have pasted the code of my Androidmanifest.xml,how does android decides which activity to launch when application starts ? In this case its the mainactivity. What changes to I need to make if I want to launch AnotherActivity when application launches?

 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.MainActivity"
            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="com.example.AnotherActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
LearningBasics
  • 660
  • 1
  • 7
  • 24
  • Does the 2 activities are the same in terms of layout and function? – JJ86 Aug 20 '14 at 11:30
  • no they are different in terms of layout and function – LearningBasics Aug 20 '14 at 11:31
  • Very well, so why don't you use one Activity and 2 fragments? If there is a determinate condition, show Fragment 1; otherwise, show Fragment 2. – JJ86 Aug 20 '14 at 11:34
  • to be honest I have just started learning android development and how know how exactly fragments work. It would be great if you could provide me with some example so that I can understand it better – LearningBasics Aug 20 '14 at 11:36

4 Answers4

3

The MAIN element specifies that this is the "main" entry point to the application. The LAUNCHER element specifies that this activity should be listed in the system's application launcher (to allow users to launch this activity).

<activity
        android:name="com.example.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Just remove the intent filter from the next activity!!

williamj949
  • 11,166
  • 8
  • 37
  • 51
  • I am not able to understand the co-relation between the main action and category. Why two variables when the task could be done with one variable? – LearningBasics Aug 20 '14 at 11:39
  • http://developer.android.com/guide/components/activities.html.Just check this link out it will surely clear all your doubts.PS Accept the answer if it has solved your initial problem – williamj949 Aug 20 '14 at 11:51
  • no need to have relation, you are just telling the OS, this activity is the main Entry point (main task) of this app, and I WANT it to appear in the system application launcher ... its almost default and sense, to set the main activity of the app to be Main Task, and show it in system app launcher – Yazan Aug 20 '14 at 11:51
  • i have accepted the answer as I answered my initial query although link you have provided is not working !! – LearningBasics Aug 20 '14 at 11:55
1

When the user selects your app icon from the Home screen, the system calls the onCreate() method for the Activity in your app that you've declared to be the "launcher" (or "main") activity. This is the activity that serves as the main entry point to your app's user interface.

You can define which activity to use as the main activity in the Android manifest file, AndroidManifest.xml, which is at the root of your project directory.

The main activity for your app must be declared in the manifest with an that includes the MAIN action and LAUNCHER category. For example:

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

Based on this, we can conclude that you currently have a faulty configuration. Only one activity can have the Intent filter for Main (so you should remove the <intent-filter> from your .MainActivity if you want to use AnotherActivity as you "Home" Activity).

Mdlc
  • 7,128
  • 12
  • 55
  • 98
  • I am not able to understand the co-relation between the main action and category. Why two variables when the task could be done with one variable? – LearningBasics Aug 20 '14 at 11:40
0
 <activity
        android:name="com.example.AnotherActivity"
        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="MainActivity" ></activity>
mdsaleem1804
  • 110
  • 14
0

As stated in our conversation, you want to show a determinate action at launch, with is own functions and layout. The solution is to use one Activity which inflate Fragment1 or Fragment2, based on your condition.

Dealing with Fragment is very difficult, but when you will master them, you will have fun. There are few example on the net about Fragment, but i tell you this: read and practice is the only way you will learn something. Copy and paste from other source code / example will not help you. Follow this links:

Good luck!

Community
  • 1
  • 1
JJ86
  • 5,055
  • 2
  • 35
  • 64