Reputation: 756
I have an app that should run on both phone and TV. In the manifest, I'm specifying the phone's launch activity with
<activity
android:name=".view.phone.MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and the TV's launch activity with
<activity
android:name=".view.leanback.MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
Instead of filtering between LAUNCHER & LEANBACK_LAUNCHER, on either device it just goes with whichever activity is declared first in the manifest. Any ideas what I'm doing wrong?
Upvotes: 12
Views: 3270
Reputation: 1817
For those who still faces this poblem in 2022. The trick is that running the app by Android Studio does not behave same as when real apk file is deployed to a real device. So your steps are:
Android Studio runs always first: activty with DEFAULT & LAUNCHER or LEANBACK_LAUNCHER filters. If no DEFAULT flag is set, AS will just grab first launcher activity mentioned in the manifest. That's because AS is unable to detect what sort of device it is deploying to. You can ensure your app will correctly switch launcher activity for appropriate device by generating apk file and installing it manually. That's how I revealed all of this.
For development purposes only you can either switch the order of launcher activities in the manifest(bad way), or to make separate run/debug configurations as explained here (the good way)
Upvotes: 2
Reputation: 1632
You are using the same Activity name MainActivity
to call both your TV and Phone App. Change one of these names and you should be good to go. As shown here in the first step, your activity name for the TV should be different than your activity name for the phone app.
Upvotes: 0