简体   繁体   English

targetSdkVersion vs. minSdkVersion:configChanges

[英]targetSdkVersion vs. minSdkVersion: configChanges

I want to avoid Activity restarts when screen orientation changes. 我希望在屏幕方向更改时避免重新启动活动。 In older sdk versions it was done by configChanges="orientation" (in the manifest). 在较旧的sdk版本中,它由configChanges="orientation" (在清单中)完成。 In newer versions screenSize was added. 在较新的版本中添加了screenSize

My minSdk is 8, the targetSdk is 17 and I find myself in a weird situation: I cannot put screenSize into configChanges (because of the minSdk) but my phone (4.1) will then destroy any activity on orientation change (because of the targetSdk). 我的minSdk是8,targetSdk是17,我发现自己处于一种奇怪的情况:我不能将screenSize放入configChanges(因为minSdk),但是我的手机(4.1)会破坏方向更改的任何活动(因为targetSdk) 。

Is there any way out? 有什么出路吗? Can I somehow prevent this destruction without having to target an outdated Sdk (but still keeping it as an option in the minSdk)? 我可以以某种方式防止这种破坏,而不必针对过时的Sdk(但仍然将它作为minSdk中的一个选项)?

You may leave your android:minSdkVersion and android:targetSdkVersion as you currently have them (8 and 17 in your example). 您可以保留android:minSdkVersionandroid:targetSdkVersion因为您当前拥有它们(在您的示例中为8和17)。

In order to be able to put screenSize into configChanges , change this line 为了能够将screenSize放入configChanges ,请更改此行

target=android-someapinumber

in the project.properties file. project.properties文件中。 Choose someapinumber as the android version where screenSize first appeared (eg, API 13). 选择someapinumber作为screenSize首次出现的android版本(例如,API 13)。

Although you asked for a specific "screenSize" problem, this solution applies to all similar situations where you want to support older devices, but at the same time you must use newer features. 虽然您要求提供特定的“screenSize”问题,但此解决方案适用于您希望支持旧设备的所有类似情况,但同时您必须使用更新的功能。 In this particular case, "screenSize" will be ignored by older devices that do not know this property, so you don't have to worry about backward compatibility. 在这种特殊情况下,不知道此属性的旧设备将忽略“screenSize”,因此您不必担心向后兼容性。 In other cases, you may have to add conditions in your source code like shown below to ensure in runtime that your app will not use features that are not available in a given (older) android version. 在其他情况下,您可能必须在源代码中添加条件,如下所示,以确保您的应用程序在运行时不会使用给定(较旧)Android版本中不可用的功能。

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) 
{
    // Code that uses features available in LOLLIPOP and newer
    // versions of android, while the app also runs on older versions
    // and supports them because of android:minSdkVersion.
}

Ah I finally figured out solution: 啊,我终于找到了解决方案:

As far as we cant affect "known suggested solution" with screenSize property as eclipse fires xml parse error on screenSize when we specify android:configChanges="screenSize", if we specify in targetSdkVersion 12 or less android os will not restart activity on orientation change. 当我们指定android:configChanges =“screenSize”时,我们不能用screenSize属性影响“已知的建议解决方案” 作为eclipse在screenSize上触发xml解析错误 ,如果我们在targetSdkVersion中指定12或更少android os将不会重新启动方向更改活动。 (Also I did now know and was using targetSdkVersion for identifying maximum supported sdk version. But as I researched again for this there is maxSdkVersion.) (我现在也知道并且正在使用targetSdkVersion来识别最大支持的sdk版本。但是当我再次研究这个时,有maxSdkVersion。)

So by this settings: 所以通过这个设置:

uses-sdk android:minSdkVersion="10" android:targetSdkVersion="12" 
android:maxSdkVersion="17"

...

android:configChanges="orientation|..."

Os will not restart activity on orientation change and application will still support minimum and maximum sdk versions but will run in compatibility mode with sdk 12 which is highest version of sdk not restarting activity which will solve the problem above. Os不会重新启动方向更改活动,应用程序仍将支持最小和最大sdk版本,但将在兼容模式下运行sdk 12,这是sdk的最高版本,不会重新启动活动,这将解决上述问题。

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

相关问题 我的minSdkVersion和targetSdkVersion是什么? - What will be my minSdkVersion and targetSdkVersion? Android SDK minSdkVersion 和 targetSdkVersion - Android SDK minSdkVersion and targetSdkVersion Flutter minSdkVersion 和 targetSdkVersion 错误 - Flutter minSdkVersion and targetSdkVersion error Android Studio minSdkVersion和targetSdkVersion警告 - Android Studio minSdkVersion and targetSdkVersion warning Android:minSdkVersion与targetSdkVersion之间的关系 - Android: Relationship between minSdkVersion and targetSdkVersion 如果targetSdkVersion = 23(棉花糖),当minSdkVersion &lt;targetSdkVersion时,Android皮棉不会显示错误 - Android lint not showing errors when minSdkVersion < targetSdkVersion, if targetSdkVersion=23 (Marshmallow) Android风格的应用程序minSdkVersion =“ 8” targetSdkVersion =“ 21” - Android style app minSdkVersion=“8” targetSdkVersion=“21” 设置正确的Android构建目标minSdkVersion,targetSdkVersion - setting the correct Android Build Target, minSdkVersion, targetSdkVersion 无法识别AndroidManifest使用过的-sdk minSdkVersion和targetSdkVersion - AndroidManifest used-sdk minSdkVersion and targetSdkVersion not recognized android:minSdkVersion,android:targetSdkVersion和“target”之间的关系 - Relation between android:minSdkVersion, android:targetSdkVersion and “target”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM