Our Lenovo tablet wasn't able to pin a task where the Home activity lived. The solution was to have two activities in two different tasks.
The Home Activity
This activity is started on boot as a launcher and it sole responsibility is to open the main activity immediately. Notice that it's transparent and has different task affinity.
<activity
android:name=".HomeActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:resumeWhilePausing="true"
android:stateNotNeeded="true"
android:taskAffinity="${applicationId}.home"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
<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>
The activity will launch the Main Activity in its onCreate
and onNewIntent
as well (because it's a singleTask
activity). Here's the code in Kotlin:
class HomeActivity : Activity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleIntent(intent)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleIntent(intent)
}
private fun handleIntent(intent: Intent) {
val i = packageManager.getLaunchIntentForPackage(packageName)
startActivity(i)
}
}
The Main Activity
This is your main activity - main entry point to your app, it can be started from any launcher. It has the default task affinity (which is equal to the application ID).
<activity
android:name=".webview.activity.RealWebViewActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|screenSize"
android:exported="false"
android:launchMode="singleTask"
android:resumeWhilePausing="true"
android:stateNotNeeded="true">
<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>