Is it possible to have two activities, one that opens up on phone and the other that opens on TV devices? I want to have a separate activity for phone and TV. I have the below xml in my AndroidManifest.xml. However, when I run the app on TV emulator, it still opens up LandingScreenActivity.
<activity
android:name=".ui.login.LandingScreenActivity"
android:exported="true"
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=".ui.tv.TVMainActivity"
android:configChanges="keyboard|keyboardHidden|navigation"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
You can keep one activity as launcher. As soon as activity opened you can check device type . If device is TV then you can open screen for TV and clear previous screen.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_landing_screen);
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
startActivity(new Intent(this, TVMainActivity.class));
finish();
}
}
You can check this - Android TV not starting LAUNCH_LEANBACK Activity