API8 to 7 compatibility - android

What is the best way to make my app originally designed for API8 to be compatible with 7? I've noticed that AlertDialog features seem to cause trouble, for instance showDialog() doesn't work.

In your manifest file you can target 8 and require 7. This will allow the app to run on 7 and show up in the market. But obviously you need to test the dickens out of the app on 7 to make sure it runs well. A good blog post on it is here
http://devtcg.blogspot.com/2009/12/gracefully-supporting-multiple-android.html
Another option that I don't think is good because you will have to support two or more code bases is to the use the multipal apk file support of the market.
http://developer.android.com/guide/market/publishing/multiple-apks.html

Related

Does every Android device contains all previous SDK versions?

I'm just wondering, if the latest Android SDK installed on a device contains code of all the previous versions as well?
So if I target API level 10 in my app and install it on a device with Lollipop, will it just take and use Gingerbread SDK exactly as it was 3 years ago?
Or is there just one codebase for all versions with a lot of checks and switches which is then run by some kind of compatibility mode picking the correct code and enabling methods of the version of SDK I target?
I read the article about android:targetSdkVersion specified in Manifest but still would like to know how this works internally.
Ok, I just surfed a bit around on the source code (which you can find here: https://github.com/android/platform_frameworks_base). I'm not an engineer of the Android framework, I was just curious about your question and here is what I found.
It does not contain all the different versions of source code. You can imagine that this would result in a nightmare if more and more versions become available. Foremost, you would have different (buggy) versions of the same method without fixing them just to keep them the same.
In the source code, you can find places like these: (see https://github.com/android/platform_frameworks_base/blob/59701b9ba5c453e327bc0e6873a9f6ff87a10391/core/java/com/android/internal/view/ActionBarPolicy.java#L55)
public boolean hasEmbeddedTabs() {
final int targetSdk = mContext.getApplicationInfo().targetSdkVersion;
if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) {
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs);
}
// ...
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs_pre_jb);
}
So the Android developers do the version check in the code where necessary. But these checks are not as necessary as you think (I guess). What's the reason for changing a method?
method is buggy: All they need to do is fix the bug. Tests will make sure that the general behavior of the method keeps the same
method is deprecated: The guys can not remove the method, all they can do is mark it as deprecated and hope for the best. Compilers will do the rest.
method behavior has to change: Well, I guess that is something they can not do easily. They can work around with version codes (which is pretty ugly and becomes a maintenance nightmare), or they just introduce a new API. That's the reason why you'll find a lot of APIs just doing the same
If you have write down a code with latest android sdk and install it in your device. It means actually you are using latest android.jar(you can see android.jar in your project) file while compiling/Executing code.
Now If you install your application in ginger bread device then android.jar(latest) has a backward compatibility(if required) to run code in Gingerbread device.and if you define target sdk version 10 and running app on Higher API level ,then it will run smooth except your compatibility behavior disable in respective device other than targeted devices.

Testing Android support on older versions

I am making application with target SDK set to 17 and min to 8.
So for some features I have to use Support library v4
Question is how can I test it works on older devices?
I am testing on my phone - which has 4.2.2; and I don't have others with older ones
Will creating emulator with 2.3.3 be true test?
tnx
Update
Just for example: I use Fragment in my code (from android.app, not from support library) - even if my minSDK is 4 - I don't see any warnings...should I?
Yes. It is an emulator (not a simulator) so it is very similar to running your code on the corresponding phone.
Another good practice is to run the Lint tests from times to times, they can detect many common mistakes in your code (including compatibility).
Your ide (both Eclipse & Android Studio plugins do this) will also display warning for obvious calls to functions that don't exist at your chosen min API level.
Most of the time emulator behave same if we consider layout view and
other stuff like look and feel performance , but that can be
difference in case of speed performance and sound quality
.
I found one online tool which are providing that service please go through that link , https://appthwack.com
apache lint (from tools) is the answer - shows all problems

Almost finished with my first Android application made with Ice Cream Sandwich and was wondering about backwards comptibility

Hello I have developed my first application for Android using the Ice Cream Sandwich SDK and I was wondering if there was a way to make this compatible for devices also running Gingerbread without having to re-do the entire program. I have tried to find the answer to this from other sources but haven't found anything yet. Thank you for your time.
Congratulations for the development of your first application ;)
It's difficult to answer to your questions without knowing what your application is using. If your application use new features of the Android ICS API, you have to implements some compatibility code (see Support package). If not, you just need to add this in your AndroidManifest.xml :
<uses-sdk
android:targetSdkVersion="14"
android:minSdkVersion="7"
/>
Note that 7 is for Android 2.1
The best way to know if you use specific API of Android 4 (ICS) is to try to launch your project on an emulator under a lower version. If this give you error(s), it's because you have compatibility problems.
Just set your build target in Eclipse to Android 2.3. If you get any compilation errors in Eclipse, than this means that you are using APIs that are not available in 2.3 and your application will crash when it is going to reach at those lines when running on 2.3> .
Just make sure youre using APIs that are there on older versions of Android. Try to read the wahts new for ICS and avoid those :) which pretty much beats the purpose of using a newer SDK that changes alot and breaks lots of things. Beware of the new layouts....

cupcake to FroYo marketplace problems (app not shown to some people - or listed on appbrain)

After reading another question, explaing to allow apps2sd I should change my android target to 2.2, keep minsdk at 4 and add installpref to manifest - this works great. However I noticed after uploading this update that my sales dropped, and free downloads. My brother in japan can no longer see my app!
My question is - how can I keep my app on the international market, and use froyos SDK?
working link:
http://www.androidblip.com/android-games/wheelz-2d-physics-platformer-90018.html
broken on appbrain:
http://www.appbrain.com/app/wheel-2d-physics-platformer/com.chozabu.android.BikeGame
Extra information!
I uploaded copy of my game - where the only change is to return SDK to 1.6
http://www.appbrain.com/app/wheelz-international-trials/com.chozabu.android.BikeGameBeta
it shows up on appbrainz!
Thanks
change my android target to 2.2, keep minsdk at 4 and add installpref to manifest
Well there's your issue right there. Cupcake is 3 Donut is 4. If it still doesn't work leave me a comment below.
Check out the version codes reference

Incorporating both Contacts and ContactsContract into an Android application

Greetings all,
I realize this issue has been posed before in other forms, and believe me, I have been searching the net for days trying to find the answer. However, I'm fairly new to Android and Java, and I need a little guidance please.
I presently have two version of my app, one for Android 1.5 and 1.6, and another for 2.0 and beyond. As you probably guessed, it's because the Contacts API is different.
I recently became aware that it was possible to combine both methods into a single app, by using dynamically loadable classes. Very cool! After days of attempts, I still haven't been able to do it successfully... or at least, it won't run.
I have come across 3 examples of how to do this - one by Google, called "Business Card", another that had something to do with Spinners, and a 3rd was something someone here created. My problem is that each one seems to me to have a showstopper.
I'm using Eclipse on Windows 7. My app was first created for A1.5, so that's the one I'm upgrading. What's happening is that my ContactsAccessorNewApi class needs to import the ContactContracts, and according to Eclipse, that won't work because my project was originally built without support for it. Hence, it won't run. I've tried adding the android.jar for SDK level 5 into the project, but that creates a whole mess of other problems.
My code for this pat of my app is exactly like the Google example "Business Card" - so if someone could help me cross this hurdle, I'd be very grateful. I'll be happy to post any code that you need to answer my question.
Thank you!
another that had something to do with Spinners
If you mean this sample project, that's mine.
I'm using Eclipse on Windows 7. My app was first created for A1.5, so that's the one I'm upgrading. What's happening is that my ContactsAccessorNewApi class needs to import the ContactContracts, and according to Eclipse, that won't work because my project was originally built without support for it.
You need to set your build target (Project Properties > Android) to be high enough that ContactsContract exists (android-5 or higher).
So long as your android:minSdkVersion in your manifest is set to support earlier versions of Android (e.g., 3 for Android 1.5), your app will still install on older emulator AVDs and devices.
I've tried adding the android.jar for SDK level 5 into the project, but that creates a whole mess of other problems.
Yeah, don't do that.

Categories

Resources