Is selectively enabling an activity-alias in the manifest with android:enabled=“@bool/tablet” or “@bool/phone” supported?

守給你的承諾、 提交于 2019-12-11 05:10:02

问题


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?


回答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.)



来源:https://stackoverflow.com/questions/14399292/is-selectively-enabling-an-activity-alias-in-the-manifest-with-androidenabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!