I want to avoid Activity restarts when screen orientation changes. In older sdk versions it was done by configChanges="orientation" (in the manifest). In newer versions screenSize was added.
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).
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)?
You may leave your android:minSdkVersion and android:targetSdkVersion as you currently have them (8 and 17 in your example).
In order to be able to put screenSize into configChanges, change this line
target=android-someapinumber
in the project.properties file. Choose someapinumber as the android version where screenSize first appeared (e.g., 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. 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. 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.
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. (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.)
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.
Related
This question already has answers here:
What is the difference between compileSdkVersion and targetSdkVersion?
(11 answers)
Closed 5 years ago.
I know that targetSdkVersion is the "highest SDK version, your app is known to work with", but what is the point? I set my targetSdkVersion 22, and my app runs fine on an api 25 device. Is it not meant to prevent installation on further api versions? If no, then what is it meant for?
android:targetSdkVersion An integer designating the API Level that the
application targets. If not set, the default value equals that given
to minSdkVersion. This attribute informs the system that you have
tested against the target version and the system should not enable any
compatibility behaviors to maintain your app's forward-compatibility
with the target version. The application is still able to run on older
versions (down to minSdkVersion).
As Android evolves with each new version, some behaviors and even
appearances might change. However, if the API level of the platform is
higher than the version declared by your app's targetSdkVersion, the
system may enable compatibility behaviors to ensure that your app
continues to work the way you expect. You can disable such
compatibility behaviors by specifying targetSdkVersion to match the
API level of the platform on which it's running. For example, setting
this value to "11" or higher allows the system to apply a new default
theme (Holo) to your app when running on Android 3.0 or higher and
also disables screen compatibility mode when running on larger screens
(because support for API level 11 implicitly supports larger screens).
There are many compatibility behaviors that the system may enable
based on the value you set for this attribute. Several of these
behaviors are described by the corresponding platform versions in the
Build.VERSION_CODES reference.
To maintain your application along with each Android release, you
should increase the value of this attribute to match the latest API
level, then thoroughly test your application on the corresponding
platform version.
Introduced in: API Level 4
Sorry for just posting straight from Android.com but it gives a clear signal of what it does.
It is the one you are developing for. App can work on higher API as well. But it is the one used for rendering layout etc.
I have defined in my manifest android:targetSdkVersion="15" and I would like to test with a device with API level equal to 17.
The minSdkVersion is set to 15.
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
I know it will work since minSdkVersion is set to a lower version than the device's one but my question is should I change the targetVersion whenever I change the device ? Isn't the targetSdkVersion supposed to be always equal to the one of the device I am testing with as it is said in the reference
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html ?
You shouldn't change the target version with every device, but with every new API level that is released.
As the webpage that you've already posted states:
As Android evolves with each new version, some behaviors and even
appearances might change. However, if the API level of the platform is
higher than the version declared by your app's targetSdkVersion, the
system may enable compatibility behaviors to ensure that your app
continues to work the way you expect.
and a few lines further:
To maintain your application along with each Android release, you
should increase the value of this attribute to match the latest API
level, then thoroughly test your application on the corresponding
platform version.
Every new API contains new features, but will also deprecate old ones; some may even get removed completely! So devices running with a higher API level might not support the same features anymore that you used in your app, which forces them to enable compatibility mode to once again be able to run the app properly.
In short, no, your targetSdkVersion should just be as high as the highest API goes. The minSdkVersion should of course be as low as possible, and you should try to avoid using maxSdkVersion, as that one will decrease the mobility of your app over time.
Even if your minSdkVersion is 1 and the targetSdkVersion is 19, new devices won't have to enable compatibility mode to run the app.
Find below what google has to say for making an application tablet optimized in its latest Google IO-13 initiatives. My question is :- Why do my app has to have min sdk version greater than 11 to make it tablet optimized? This means my application is not for tablets if I am supporting gingerbread phones which is still active in lot of devices.
At a minimum, check the element to make sure that:
targetSdkVersion is declared with value 11 or higher (14 or higher is recommended), OR
minSdkVersion is declared with value 11 or higher.
If a maxSdkVersion attribute is declared, it must have a value of 11 or higher. Note that, in general, the use of maxSdkVersion is not recommended.
From the <uses-sdk> documentation:
[...] setting [the targetSdkVersion] value to "11" or higher allows the
system to apply a new default theme (Holo) to your app when running on
Android 3.0 or higher and also disables screen compatibility mode when
running on larger screens (because support for API level 11 implicitly
supports larger screens).
There are a few key things to note here.
You don't need to set minSdkVersion to 11. They suggest setting either minSdkVersion OR targetSdkVersion to 11. Doing either will have the same effect for tablets.
You can have an application that runs on tablets just fine without doing this. It simply will use screen compatibility mode, which is not optimal.
If you aren't targeting a higher API version (or implicitly doing so with minSdkVersion), then your app will also not use Holo (without a library), which is a standard UI expectation for apps on newer (3.0+) devices.
I'm new in the android developing.
I need to write some simple application - and i need to decide what will be the target version.
I don't know how to decide this - because i want to support the most newer version with all the new abilities - but i also want to support the maximum devices ( there are few devices that have old versions )
So, How to decide what will be the target version ?
In the Android Manifest.
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
Set your android:targetSdkVersion to whatever is the last Android SDK version.
Quote from Bruno Oliveira at Google IO:
targetSdkVersion does not affect the minimum SDK level required to run your application. It should always be the latest version that you are aware of.
The only reason you could have to use a lower version would be to detect incompatibilities, but that is not a good reason because Lint does this better.
BUT set your android:minSdkVersion to as low as your app will run on. That's the important one.
For instance, my app uses very new features, but I set android:minSdkVersion to 3 (which means Android 1.5). My code detects Android 1.5 devices, and uses less-shiny controls on them, but still runs correctly.
Detection code sample:
if (android.os.Build.VERSION.SDK_INT > 4) {
ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.UP);
}
So, here is my suggestion:
Set android:minSdkVersion to 3
Everytime you discover an API is not present at that level, ponder whether the loss of potential users associated with increasing this number is worse than spending the time to implement a workaround.
I would say just start off with the lowest possible target and then as you encounter stuff that you can only do with a higher target you will have to change the target to the higher one. Using APIs that only work on for example 2.3 will show errors if your target is lower (because the APIs won't exist there).
Also you should consider the current state of the "fragmentation" to se what targets are actually being used out there. Looking at this chart (from October 5) maybe it could be worth just starting with 2.1 and se if it is high enough for all the things you want to do:
http://cdn.devilsworkshop.org/files/2011/09/android-OS-fragmentation-report.jpg
I built my applications without specifying a minimum sdk in the beginning. However after I added that line to publish to market I found my applications are behaving very differently for example buttons are smaller, etc... In particular I'm having problems with an application that records sound which was working fine when no minimum sdk was specified, but crashes when I specify one. I've tried specifying the minsdk to that of my phone which is 7, but that doesn't seem to help.
What's the default minimum sdk when none is specified? I just want my application to run like it does normally.
If you don't specify a minimum or target SDK version you get a lot of compatibility mode behavior. The device you're running on is probably a HDPI device and you were probably looking at a UI scaled for compatibility mode before you added the minSdkVersion, hence the smaller buttons - your app is now running at the device's native resolution.
Apps that target SDK 3 and below acquire several permissions by default that must be explicitly requested by apps targeting newer SDK versions. Check your exception message when your app crashes, it might be a security exception for a permission that you need to explicitly request in your manifest.
See the following link for more info: http://developer.android.com/guide/practices/screens_support.html