Change Android App starting activity - android

I'm trying to change the start up activity.
I created an activity when the app loads but I want to add a screen before that, I'm not sure where to change the Android manifest to load a certain layout/activity when the app starts.

The startup activity [Launcher Activity] is declared in the projects' AndroidManifest.xml file
Look for that activity tag in the manifest which looks like this
<activity android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Look at the attribute android:name. Main is the class which is launched when the app starts. Currently your calendar activity name should be there. Change that to the .classpath of your activity that you want to launch.
That should do it. You may also want to do the hello world application in the tutorials and go through the docs a little to see how Android Applications work.
From here

Just create another activity and set it as Launcher Activity and after a timer (if that's your achieve) just call the other activity!

Related

Two Instances opened When opening application from dynamicaLink and from launcher icon?

I ran into an issue in my Android Application where whenever I open my app through a dynamic link shared on Whatsapp, it will open in the same Whatsapp Application. I can see by going to the recent task that there is only one Application in a recent task which is Whatsapp and I can see my application inside it.
If I open my app from launcher icon then it will also create a new Application and there will be two application in recent tasks. My Splashscreen looks like this -
<activity
android:name=".SplashScreen"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You should added attribute in your activity
android:launchMode="singleTask"
In general it is better to use a dedicated Activity for sharing from other applications. Another app should not launch your main (root) Activity to share, it should launch a different Activity. That Activity can then launch your main (root) Activity in a new task (if necessary). You need to consider the user's behaviour and make sure that you don't confuse the user with multiple tasks.

How to change the main activity shown on the emulator to another activity?

I am having a problem with setting the main activity that is supposed to be shown on the emulator. Initially I already have an main activity (my first page) that will be shown when I first start up my emulator. But then now I wish to change the first activity that will be shown first when I run my application. I have changed the name of the activity in my android manifest however the first activity that runs is my previous activity instead of the new one that I have created. I have no idea why the new activity won't show although I have changed the android manifest Anyone has an idea on solving my problem? Thanks in advance. Any help would be greatly appreciated.
Specify the activity which you want to be launched initially with the intent filter in your Android Manifest.xml
<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>
<activity android:name=".FirstAvtivity" />
In the Android Studio Run -> Edits Configuration menu, you can change the Launch activity manually.

Android Manifest

I found a code on internet for displaying a splash screen before starting an android application. He made some changes in the code which he didn't explain well.
He used Launcher for Splash screen Activity and used Default in main android Activity.
He used Package name with main class name instead of pre-generated code for android:name in action.
Here is the code.
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StartingPoint"
android:label="#string/title_activity_starting_point" >
<intent-filter>
<action android:name="com.alfred.splashscreenwithsound.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
So my question
What is the difference between LAUNCHER & DEFAULT.
Is there any good behind changing the android:name in action to the package name.
when you write LAUNCHER it will launch application with Icon and if you remove it it will not show you the application Icon
"android.intent.category.LAUNCHER" serves as our main entry into the app.
android.intent.category.DEFAULT be set if the Activity should be an option for the default action (center press) to perform on a piece of data.
Refer this
LAUNCHER is your main page DEFAULT is your Activity page when load the app. on device first LAUNCHER will open. Then If you trigger your activity page DEFAULT will open.

Is there a way to rename the android program shortcut on desktop?

In some modified version(for example, CM7), you can long press the shortcut to rename it.
But CM7 have some bugs now.
I would like to know is there a way I can do that? modify the database, change the programs code or resources is OK. Thanks.
You need to change AndroidManifest.xml file. You should find the activity that is launched by this icon and change android:label value there. This will change the icon name in Application Launcher and on Home Screen.
It should looks something like this:
<activity android:name=".HelloWorld" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The activity definition in AndroidManifest.xml should contain MAIN and LAUNCHER in its intent filter (otherwise the activity will not be visible in Application Launcher).

Help with first Android Activity

When my app first opens my first activity that is presented to the user can vary based on configuration options. I only know how to hard code the first activity that runs when the app is running by adding something like this in the Manifest
<activity android:label="#string/app_name" android:name=".MyFirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Where MyFirstActivity is the class name of the first activity class to be run. How can I dynamically select which activity to run first when the app is first launched rather than hard code it in the manifest?
Thanks!
Option #1: In onCreate() of MyFirstActivity, call startActivity() for the right activity, then finish().
Option #2: Define several activities with the LAUNCHER <intent-filter>, all but one disabled. On first run (or as needed), enable the right activity and disable the others. Downside: may require a phone reboot to update the launcher, since not all home screen launchers will detect your change.
Option #3: Redesign your GUI such that this is not an issue.

Categories

Resources