Manifest for home intent and launcher intent - android

What I have done is made a home screen application. Aka when you press home, it goes back to my app.
What I am struggling with though, is adding a normal launcher side to it, aka making it appear as an app in the apps menu. My intention is to create a simple screen that tells you and provides button access to change the home default settings. A wizard/setup guide in effect.
However, I am not sure how to have both together in one app, as it is something new to me.
The home bit works, it is the second activity that doesnt.
Manifest:
<activity
android:name=".HomeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/FullscreenTheme">
<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>
<activity android:name=".LauncherActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

Add the android.intent.action.MAIN inside the LauncherActivity Intent filter so it looks like this
<activity
android:name=".HomeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask"
android:theme="#style/FullscreenTheme">
<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>
<activity android:name=".LauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

Related

Adding multiple intent filters to MainActivity doesn't work?

I have MainAcitivty on which I am adding multiple intent-filters, with a purpose to open the MainActivity.
But the problem is that onNewIntent() is called but intent.action is always main, even when it should be VIEW_RICH_PUSH_MESSAGE. If I remove the second intent filter and add that to another new Activity, it will work for that Activity.
What I want is to define multiple intent filters for one Activity but I couldn't figure out the problem.
My manifest is defined as follows:
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.urbanairship.VIEW_RICH_PUSH_MESSAGE" />
<data android:scheme="message"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
Any help is appreciated.

ActivityAlias label not taken from resource

I have two launcher in my app, one is a normal activity with the intent-filter for launcher/main and the other one is an activityAlias.
For both, I supply labels in the manifest via my strings.xml resources.
The reason for this is, that I want to provide different labels in different
locales.
Unfortunately only the label of my activity is changed accordingly to the
language selected in the android settings.
Why is that?
<activity
android:name=".MainActivity"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Transparent">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
and the alias
<activity-alias android:name=".MainAlias"
android:enabled="true"
android:exported="true"
android:icon="#drawable/alias_icon"
android:label="#string/alias_label"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>

Android - How to change entry point of App without removing shortcuts?

So, in a previous version of my Application, I had an entry point named MainActivity
<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>
This version, I have a new entry point for my application, which then re-directs to MainActivity or another screen programmatically. Here are the two activities:
<activity
android:name=".NewEntryPoint"
android:label="#string/title_activity_second" >
<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="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I removed the action.MAIN from main activity and set it to my NewEntryPoint. However, any users that had the application as a shortcut on their homescreen will lose the shortcut. Keeping the Launcher category in MainActivity didn't help either.
Is there a way to change entry point of my App without removing shortcuts?
Thanks!
I believe you could use activity-alias for this, but I would question whether or not it's worth the future maintenance just to avoid users having to add a shortcut to your app again. Something like this:
<activity-alias
android:name=".MainActivity"
android:targetActivity=".NewEntryPoint">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>

Two main activities in AndroidManifest.xml

I would like to have two main activities in my app. So in my manifest I put:
<activity
android:name="mypackage1.MainActivity"
android:label="#string/title_activity_main">
<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="mypackage2.MainActivity2"
android:label="#string/title_activity_main2">
<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>
Two icons are created in my apps menu. But when I click on each of them the first activity MainActivity is always launched. Is it possible to have two main activities? If so, what's wrong with what I did?
Thanks
The LAUNCHER intent filter is what determines what shows up in the app drawer/launcher. That is why you get two icons shown up.
However, you also set the DEFAULT intent filter, which sets the default Activity for the whole package. Since you set it twice, you get the problem of precedence of the first/latest registered. When you remove the DEFAULT filter, you will be able to start whatever you click on in the launcher.
In short, remove the following line from both Activities:
<category android:name="android.intent.category.DEFAULT" />
Yes, just mark two or more of your <activity>s as LAUNCHER within your manifest.
In addition you have to set the android:taskAffinity attribute on both of your Launcher-Activities which specify the exact package and Activity to be started.
<activity android:label="MyApp" android:name=".MyApp" android:taskAffinity="com.example.MainActivity">
<intent-filter>
<action android:name=".MyApp"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:label="Settings" android:name=".Settings" android:taskAffinity="com.example.SettingsActivity" >
<intent-filter>
<action android:name=".Settings"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Use android:documentLaunchMode="intoExisting", to launch a separate task based on the intent's Component name and data URI. Without this (by default), the activity will share all the same activities, as android:documentLaunchMode default to none.
intoExisting: The system searches for a task whose base intent's ComponentName and data URI match those of the launching intent. If the system finds such a task, the system clears the task, and restarts with the root activity receiving a call to onNewIntent(android.content.Intent). If the system does not find such a task, the system creates a new task. source
<activity
android:name=".CameraActivity"
android:exported="true"
android:documentLaunchMode="intoExisting"
android:label="#string/app_1_label">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ProfilePoseNetActivity"
android:exported="true"
android:documentLaunchMode="intoExisting"
android:label="#string/app_2_label">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The intention of potroae using task affinities to prevent your 2 activities from sharing the same task. However, it is annoying to have to select a task name, i.e. com.example/SettingsActivity for every task you want to launch separately.

Android application label changes

I'm tearing my hair out over this one. I've got an application for which I use a short title to display in the launcher etc. I've also got a longer string that I use to display at the top of the screen from within the app (where there is more space). The observant will note that I do try to set NoTitleBar but not all devices appear to obey this style, which is why the long title must remain.
The problem I am having is that the label used on the app icon in the laucnher & desktop seemingly randomly reverts to the long string on some devices. On other devices everything is fine. I can't determine whether there are some artifacts lingering from an old version of the app, if its something I am doing wrong or if it's a bug with certain devices. The fact that its happening across multiple devices/vendors makes me tend to doubt the later.
My AndroidManifest consists of the standard stuff; an application tag containing a variety of activities. For reasons I dont understand, I was able to fix the problem on some devices by adding an android:label to all my IntentFilters.
This is basically what my AndroidManifest looks like:
<application android:label="#string/global_app_short_name" android:icon="#drawable/app">
<activity android:name=".HomeActivity"
android:launchMode="singleTask"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter android:label="#string/global_app_short_name">
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".A1"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter android:label="#string/global_app_short_name">
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".A2"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter android:label="#string/global_app_short_name">
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".A3"
android:launchMode="singleTask"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="stateHidden">
<intent-filter android:label="#string/global_app_short_name">
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".A4"
android:launchMode="singleTask"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter android:label="#string/global_app_short_name">
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".A5"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter android:label="#string/global_app_short_name">
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".A6"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter android:label="#string/global_app_short_name">
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".A7"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter android:label="#string/global_app_short_name">
...some stuff...
</intent-filter>
</activity>
</application>

Categories

Resources