1

To avoid some Tablet/Phone wiring, I want my app to issue itself an intent via an activity-alias, and make the manifest system deliver it to the main activity (for tablet) or a new activity (for phone).

If I have this in my manifest:

<activity-alias android:name="my.app.WebContent"
              android:targetActivity="my.app.activities.Home"/>

then all is well, and

Intent {
    act=android.intent.action.VIEW dat=http://www.app.my/url
    cmp=my.app/.WebContent (has extras) }

is delivered as expected.

If, however, I have this in my manifest:

<activity-alias android:name="my.app.WebContent"
              android:enabled="@bool/has_one_pane"
              android:targetActivity="my.app.activities.WebContent"/>
<activity-alias android:name="my.app.WebContent"
              android:enabled="@bool/has_two_panes"
              android:targetActivity="my.app.activities.Home"/>

with this in values/res.xml

<resources>
    <bool name="has_two_panes">false</bool>
    <bool name="has_one_pane">true</bool>
</resources>

and this in values-large/res.xml, and values-sw600dp/res.xml:

<resources>
    <item type="layout" name="content_frame">@layout/activity_item_twopane</item>
    <bool name="has_two_panes">true</bool>
    <bool name="has_one_pane">false</bool>
</resources>

then my code filters out the intent as 'undeliverable' according to PackageManager.resolveActivity().

It seems that values/res.xml overrides values-anything/res.xml, even though values-large is supposed to override values/res.xml for large displays.

Is this a bug in Android, or have I misunderstood how this should be done?

android.weasel
  • 3,343
  • 1
  • 30
  • 41

1 Answers1

1

No, it's not supported because things like screen width (res/layout-w600dp) can change by orientation but Google didn't apparently notice that 'smallest width' (res/layout-sw600dp) isn't affected by that. See Fragment Orientation Change - Better Test than for Landscape

Note too that the workaround suggested in How to specify Activities that are only for phones or tablets on Android doesn't work for competing <activity-alias> because you cannot construct a ComponentName to uniquely select between aliases of the name name.

(Unless it's possible to disable only one of the targeted activities and rely on ordering within the manifest to swap between the alternatives, but that has fragility issues.)

Community
  • 1
  • 1
android.weasel
  • 3,343
  • 1
  • 30
  • 41