Search code examples
androidandroid-manifestandroid-api-levels

AndroidManifest attributes depending on API level


Using startActivityForResult doesn't work properly in Android < 5.0 when using launchMode singleInstance or singleTask. However, I'm using that launchMode to avoid WebView reload:

android:alwaysRetainTaskState="true"
android:documentLaunchMode="never"
android:launchMode="singleInstance"

I understand there's no possible workaround around the first limitation.

Is there a way to make those Manifest attributes variables, depending on the API version?
(I'd use those three attributes with specified values for Android > 5.0, and a launchMode="standard" for Android < 5.0. Very similar to this, only that I can't find a way to define documentLaunchMode and launchMode; only alwaysRetainTaskState since it's a bool).


Solution

  • You can create an <activity-alias> that uses the same underlying Activity, but has different manifest parameters (launch mode, etc.). Then you just need to make sure that you launch the correct Activity (either the original one, or the alias) depending on what version of Android you are running on.

    Depending on your architecture and the nature of your problem, this may or may not be an appropriate solution.