oleynikd oleynikd - 3 years ago 93
Android Question

Android universal app for both Mobile and TV (Lollipop)

Is it possible to create an universal Android App for both TV and Mobile but with different main Activities, Themes, Styles and so on?

I tried adding activity to the Mainfest file:

<application
... >
<!-- Mobile -->
<activity
...>

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

<!-- TV -->
<activity
...
android:theme="@style/Theme.Leanback">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>

</activity>
</application>


But as I understand I cant have 2 "android.intent.action.MAIN" activities?

When starting new project in Android Studio and selecting both Mobile and TV as supported "form factors" it creates project with 2 separate modules, so actually these are 2 separate apps, right? But I want to be able to share 90% of code between them. How do I do that?

Thanks in advance.

Answer Source

You can make a new module like a library for both project, and then import inside each gradle and you can share common code between both modules.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download