How to specify which activity starts on app launch? - android

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.

Related

Trouble understanding how to set my login activity to the launcher activity in the Android manifest

I want to change my manifest so that the Login Activity is the first activity to start on the phone. The login activity checks the sharedpreferences to see if a user has login info saved. If they do it logs them in. Im pretty sure I need an intent-filter in login activity with <category android:name="android.intent.category.LAUNCHER" /> but I dont get what I should put for the action.
Heres my manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.incubatorcle.dinahealth.MainActivity" />
</activity>
<activity
android:name=".UserOnboardActivity"
android:label="#string/title_activity_user_onboard" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login" >
</activity>
</application>
You need:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
ACTION_MAIN action indicates this is the main entry point and does
not expect any intent data.
CATEGORY_LAUNCHER category indicates
that this activity's icon should be placed in the system's app
launcher.
Your MainActivity need to look like this:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.yourpacgagename.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Your Login activity need to look like this:
<activity
android:name=".LoginActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
As your question is answered by #wariaten
Here is another way to do the login check
Add a third activity (where you check the SharedPreferences and launch the LoginActivity or the HomeActivity) and set it as the launcher as suggested by #wariaten

Android app with 2 launcher icons with separate taskAffinity

I have app with 2 launcher icons and 2 different Activities. Manifest file is as like below:
....
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:taskAffinity="my.package.com.MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MySettings"
android:label="#string/settings"
android:icon="#mipmap/ic_launcher"
android:taskAffinity="my.package.com.MySettings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
....
I want MyActivity to be default screen to be opened after installing, so i used .category.DEFAULT.
action.MAIN and category.LAUNCHER are to show two separate launcher icons (1 for MyActivity, 1 for MySettings).
Problem: When i open MyActivity, MySettings screen is also gets opened. I want each launcher icon to open its corresponding Activity only. I have used taskAffinity for each Activity to solve problem but it did not work. I think to make taskAffinity work, Activity must be started with flag Intent.FLAG_ACTIVITY_NEW_TASK which i can not in my case (both are launch Activities).
I have also tried to use android:launchMode="singleTask" but it did not work either.
How to make each launcher icon to open only its Activity ?
UPDATE: Sorry, i realized MyActivity does not open MySettings, it seemed so though. MyActivity did not have UI, so it showed blank screen which is similar to MySettings. taskAffinity works correct. I have added android:theme="#android:style/Theme.NoDisplay" to MyActivity to hide UI.
Just use two different images for your apps to launch.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<activity
android:name=".MySettings"
android:label="settings"
android:icon="#drawable/ic_launcher2"
android:taskAffinity="my.package.com.MySettings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I solved that way:
<activity
android:name="andynaz.android.hyperfcalc.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="andynaz.android.hyperfcalc.MainActivity2"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I did not use the taskAffinity, but I indicated the fully specified name of Activity classes (other than using 2 different images).

How to determine which activity begins when i launch application?

I want know how i can determine which activity begins when i launch application ?
I have two Activity. MainActivity and Activity2. Which is the way i can code my application start every time in MainActivity ?
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="#string/app_name"
android:screenOrientation="portrait"/>
<activity
Check out your AndroidManifest.xml file. In there you have each of your activities listed, then you can simply specify which one you'd like to be the default startup by adding this "intent-filter" shown below.
<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>

My App Installs Two Applications - Android

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

no launcher activity was found even if i had declared one in the manifest

i declared the report file as my launcher. so its supposed to launch first when the app is started first. or do i get something wrong.
i get the error. no launch activity was found. thx guys
<activity android:name=".report" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.REPORT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main" android:label="#string/app_name">
<intent-filter>
</intent-filter>
</activity>
You need to change the action:name from .REPORT to .MAIN. The action name corresponds to the intent action and not to the Activity name.
Fixed version of the above:
<activity android:name=".report" 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=".Main" android:label="#string/app_name">
</activity>

Categories

Resources