Is it possible to have multiple launcher activities on android tv like on mobile android? I've tried to declare two activities with intent filters like this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
but it doesn't work. I see two icons but they launch the same activity. Thanks in advance!
Related
I noticed that
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This part above can make icons.
So, This code will create two icons after installing one apk. But those launch different activity each-A_Activity or B_Activity
<activity
android:name=".ui.A_Activity"
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=".ui.B_Activity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But anyway, this acts like one app after launching one of them. After launching A_Activity, it can reach the other Activities or Resources that B_Activity moves to or uses if the implementation is the similar or the same.
However, what I want to know is making two different names for each icon. Mine has two icons but the same name. Is there any way to give different app names for them? Because I wanna test two different modes at the same time after installing it.
The text underneath the icon on the HOME screen is taken from the
android:label="..."
attribute of the <activity> description in the manifest. If you don't provide this, it uses the android:label of the <application>.
So all you need to do is to provide different android:label strings for each <activity> in the manifest.
In the manifest, it is possible to specify multiple activities:
<activity
android:name=".Activity0"
android:label="#string/app_name0">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity1"
android:label="#string/app_name1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
These will then result in two icons, placed on the launcher. I was wondering if the application can register more icons programmatically (based on application settings / user interaction with the app). Note that they would not need to run different activities, a single activity, starting with different intents would also work. Is this possible, or does one have to use widgets?
no need to use widgets - you can just add dummy activities that start your needed activity with the right parameters and then finish - you can also exclude them from recents so the user does not see the activity at all.
You can also install a shortcut by runtime - but then you need permission: INSTALL_SHORTCUT
I wanted to register my launcher activity so it could be started by both clicking on icon and opening link with a custom scheme. I managed to make it work but am questioning is this correct way. This is the relevant part of my manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="my.sheme" />
</intent-filter>
This does work but I was wondering should I register both actions under same intent filter. I tried just moving tags from second filter to the first one but then my activity doesn't show icon on install. Is it possible to do it this way and I just made some small syntax error(or broke some undocumented order of declaration rule) or is my thinking completely wrong on this and there are deeper reasons why this doesn't work?
NOTE:I do set android:exported="true"but android.intent.action.MAIN works even without it because it becomes exported anyway if you use action.MAIN
As the Android documentation states:
When you want to handle multiple kinds of intents, but only in specific combinations of action, data, and category type, then you need to create multiple intent filters.
Otherwise you can group them into one intent-filter.
I'm just getting started with the Android SDK and after I just understood how to open another view with a MenuItem. I'm now facing a problem that it is showing me my two activities as separated applications installed?
I've created a new activity and a new xml file (layout) and when I touch the menuItem in the ActionBar in my first view it opens the second view.
Any idea to work around that?
It sounds like you have the <intent-filter> set as
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
for both activities. This will create a launcher icon for each and make each an entry point for your app
Docs
Most likely, you've included the following intent filter in both your Activities:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This is meant to be put in only those Activities which you want shown in the app list.
I was looking at sample android applications, and I noticed all of the activities in the manifest had:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
I noticed that my activities start fine without this intent-filter. So what is the point of this intent-filter and is it best to include them?
<intent-filter> has to be given for atleast the first activity which you want to start in your application.
The lines :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
if given to an activity, then its purpose is to enable the user to interact with the activity that is either VIEW or EDIT or INSERT.
DEFAULT category is required for all filters except for those with MAIN action and LAUNCHER category
It is not necessary to give the <intent-filter> to every activity, but as said in the developer's guide it would be a better practice to use.