简体   繁体   English

对Activity的最低SDK版本支持

[英]Minimum SDK version support for Activity

The application have some activities, some runs on higher version only. 该应用程序有一些活动,有些只在更高版本上运行。 But since the activity support mimeType of intent-filter , so I've no control over its launch. 但由于活动支持intent-filter mimeType ,所以我无法控制它的启动。

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="image/*" />
        </intent-filter>

Like the activity having this intent-filter can be launched by lowered version than it must not. 就像具有此intent-filter的活动可以通过降低版本而不是必须启动。 Eg : The activity must run in version 11 and above but android will still show it inside chooser dialog of image in lower versions. 例如:活动必须在版本11及更高版本中运行,但android仍然会在较低版本的图像选择器对话框中显示它。 Is there a way to avoid this situation ? 有没有办法避免这种情况?

You would have to have a 'controller' activity with the intent-filter . 您必须使用intent-filter进行“控制器”活动。

When this activity starts, it would check the current SDK level and then forward on the Intent to either the lower or higher SDK activity, then finish() itself. 当此活动开始时,它将检查当前的SDK级别,然后将Intent转发到较低或较高的SDK活动,然后是finish()本身。

In your situation this can give you further flexibility later, say you want to direct tablets to a 3rd activity. 在您的情况下,这可以为您提供进一步的灵活性,比如说您希望将平板电脑定位到第三项活动。


Another argument could be that your Activity should test the SDK level and then just swap Fragments out dependent on this. 另一个论点可能是你的Activity应该测试SDK级别,然后根据这个来交换Fragments ie your Activity is SDK agnostic but it is a controller for the correct Fragments to show. 即您的Activity与SDK无关,但它是一个控制器,用于显示正确的片段。

References: 参考文献:

http://developer.android.com/training/basics/supporting-devices/platforms.html http://developer.android.com/training/basics/supporting-devices/platforms.html#version-codes http://developer.android.com/training/basics/supporting-devices/platforms.html http://developer.android.com/training/basics/supporting-devices/platforms.html#version-codes

http://developer.android.com/training/backward-compatible-ui/abstracting.html http://developer.android.com/training/backward-compatible-ui/abstracting.html

http://developer.android.com/training/backward-compatible-ui/using-component.html http://developer.android.com/training/backward-compatible-ui/using-component.html

As you see from the references, you should go read the training docs 正如您从参考文献中看到的那样,您应该阅读培训文档

If you're looking for only XML configuration I can suggest you the way, how it's done in Android API Demos. 如果你只是在寻找XML配置,我可以建议你如何在Android API演示中完成它。

They declare Activity in the AndroidManifest as disabled or enabled depending on API version like this android:enabled="@bool/atLeastHoneycomb" , where @bool/atLeastHoneycomb is just a flag that is set to true in values-v11 and to false in the default values folder (you can check Android API Demos, as I said previously, for more details). 他们将AndroidManifest中的Activity声明为禁用或启用,具体取决于API版本,如android:enabled="@bool/atLeastHoneycomb" ,其中@bool/atLeastHoneycomb只是一个在values-v11 @bool/atLeastHoneycomb中设置为true且在false中设置为false的标志默认values文件夹(您可以查看Android API演示,如前所述,了解更多详情)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM