This question already has answers here:
Change application's starting activity
(13 answers)
Closed 4 years ago.
I want to create own activity as main activity rather than using default MainActivity.
How can I define that in android manifest?
In your manifest file , use the below code to declare an activity as a launcher activity:
<activity android:name=".yourActivityName" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
From Android Developer docs:
ACTION_MAIN activity: Start up as the initial activity of a task, with no data input and no returned output.
CATEGORY_LAUNCHER: The activity can be the initial activity of a task and is listed in the top-level application launcher`.
In AndroidManifest.xml file inside application tag add an activity tag and remove action MAIN from old activity tag set that as default
<application...... >
<activity
android:name=".DefaultActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".NewActivity"
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>
You can use in manifest file:
<activity
android:name=".DefaultActivity"
android:label="#string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".NewActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It is very important:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
It's Simple. In your android manifest file add,
<activity
android:name="Your Activity Name"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In Xamarin, you can add MainLauncher = true above class definition like this:
[Activity(Label = "UserActivity", MainLauncher = true)]
public class UserActivity : ListActivity
Related
I have in my AndroidManifest.xml two activities that I could launch
<activity android:name=".ExperimentActivity"
android:label="Experiment">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I install, there's two icons, Main and Experiment. However, when I launch, both also launch the ExperimentActivity.
Did I miss anything?
Please add the exact package like
android:taskAffinity="com.yourpackage.MainActivity"
and
android:taskAffinity="com.yourpackage.ExperimentActivity"
to your activity tag .
Hope this helps.....
So, normally you only launch the Main Activity, which is declared as your launcher in the manifest. All other activities then get launched from the Main Activity.
You should only declare one Launcher Activity in your manifest.
E.g.:
<activity android:name=".ExperimentActivity"
android:label="Experiment">
<intent-filter>
<!-- declare your own filters if you need them -->
<!-- for example parent activities -->
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I found another way of doing so, which is to add the following to my ExperimentActivity scope.
android:launchMode="singleInstance"
i.e.
<activity android:name=".ExperimentActivity"
android:launchMode="singleInstance"
android:label="Experiment">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Currently my ActivityMain.java is main in my app android. How can I change the activity that started with my android app ?
Thank you so much.
In you manifest, put
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
between Activity tag
<activity
android:name="com.some.activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Whenever I try to run my App, it installs two app in the emulator/device. I only want to Install my Main Activity, but the Splash Activity installs also. I know the problem is in the Manifest. Can anyone help me please? Here is my code:
<activity
android:name="com.android.upcurrents.launcher.SplashActivity"
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.android.upcurrents.MainActivity"
android:label="#string/app_name" />
You need to have only one activity to be declared as the launcher. So, remove the intent-filter from within the SplashActivity's tag, and add it to your MainActivity. The Launcher intent-filter should be present in only one of the activities in your manifest file.
It installs based on the intent filter you have provided.
Remove the following intent filter from SplashActivity and then put it in Main Activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
try this:
<activity
android:name="com.android.upcurrents.launcher.SplashActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.android.upcurrents.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>
I had this same problem but I fixed it with the making sure you only have one activity with:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
In my code I had two activities with that intent-filter, which caused two applications to be installed on my device.
We have the same problem but i fixed it this way
before my code below in manifest
<application
android:debuggable="true"
android:allowBackup="true">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.noupdate.apptest_noupdate.MainActivity"
android:icon="#drawable/ic_launcher"
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>
Notice that in the SplashActivity inside the intent is this code
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
i only deleted the category
<category android:name="android.intent.category.LAUNCHER" />
So after i deleted the intent-filter category in splash it didn't install two app icon but only one for main the code will be like this notice that the intent-filter category is deleted
<application
android:debuggable="true"
android:allowBackup="true">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.noupdate.apptest_noupdate.MainActivity"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.NoTitleBar"
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>
it really helps
All
I want to set two action in launcher activity in manifest as like below, So it's possible.
<activity
android:name=".MainActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.example.sampleapp.android.widget.buttons.ButtonWidget.ACTION_WIDGET_CONFIGURE"/>
</intent-filter>
</activity>
Is it possible?
Try to define action with multiple intent-filter
<activity
android:name=".MainActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.sampleapp.android.widget.buttons.ButtonWidget.ACTION_WIDGET_CONFIGURE"/>
</intent-filter>
</activity>
check this post Default when using multiple Actions in Intent-Filter
I have an app with 3 different activities in it. When I launch the app one of the activities always starts first. But I want a differnt activity to start before the one that is currnetly starting first.
How would I change this to make a differnet activity start first?
Open your AnroidManifest.xml file and set the Launching Activity using the intent-filter tag as follows,
<activity android:name=".LaunchingActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You need to add an intent filter to the activity you want to start on application launch in your app's AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
You need to make changes in AndroidManifest.xml file...
<application
android:icon="#drawable/image"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name="define the activity which you want to start first here" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FirstActivity" >
</activity>
<activity android:name=".SecondActivity" >
</activity>
<activity android:name=".ThirdActivity" >
</activity>
</application>
Hope this will help you....
In your AndroidManifest.xml put the following:
<activity android:label="#string/app_name"
android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
The intent-filter inside the activity tells Android which Activity to launch.