About new methods and deprecated methods in Android APIs - java

I'm new to android development.
I'm studying with outdated books, so I'm really confused about new methods.
I'm going to make a simple and light app which can be run even on old devices.
So when I created a new android project, I set "Minimum Required SDK" to API 8, "Target SDK" to API 22 and "Compile With" to API 22.
Does this setting mean the app can work on the devices of API 8, even though I use the methods of API 22?
I'm asking this question due to deprecated methods.
I completed almost a half of my app developing using deprecated ones.
Can I just replace them all with new ones?
Or do I have to prepare multiple codes using different methods to support different platform versions?
(deprecated methods for older versions, and new ones for newer versions?)

Does this setting mean the app can work on the devices of API 8, even though I use the methods of API 22?
Yes. min sdk version is used to restrict the devices running OS with API level < minsdk from using app. Your app won't be shown in the play store for those devices.
I'm asking this question due to deprecated methods.
I haven't faced any issues till now due to depreciated methods. However, I would suggest to use min sdk version as 14 as Google has introduced many UI tweaks and enhancements. If you do some market research, using minsdk version = 14 would cover around 85% android market.
Can I just replace them all with new ones?
Yes, you can.
Or do I have to prepare multiple codes using different methods to support different platform versions?
(deprecated methods for older versions, and new ones for newer versions?)
You can do it also. Older versions do not have support have fragments. Fragments improve user experience drastically for tablets. Similarly, material design for Lollypop devices is awesome. Thee are few examples where you can opt for API level specific implementation. However, it is better to switch for api level >= 14

To clear up your confusion:
Minimum Required SDK
The minimum version of Android you're going to support. To target the largest market share, I recommend API level 14 or above.
Generally, the lower the number, the more Android devices you're targeting.
Target SDK
Basically, all this is saying is what SDK have you tested your app with. If that's KitKat then you can write in the number 19 which is the API number of KitKat, for example. You can find a list of API numbers here. As you test your app with higher and higher versions of Android, you can increase that number.
Setting the Target SDK to be a higher number will mean that you target a lot more devices.
Compile With
Specifies what API number of Android you want to compile your app with.
By default this is the latest version of Android available in the SDK Manager. Should be set high to improve user experience.
Deprecated Methods
As to your question about deprecated methods: You can continue using them. They are deprecated in favour of a newer alternative that may or may not be better in terms of functionality.

Deprecated methods will still work, the deprecated keyword just tells you that there is a newer preferred way to do it. Android is really good at backward compatibility so something compiled for API level 8 should mostly work on newer devices to.

You're going to have to use multiple code branching on version. You can check your system version at runtime like this:
private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
API 8 is really old. Have a look at the version pie chart
You can find more information about this on the Android developers website

Related

Using multiple sdk versions in my project

I am currently working on an app using some features that are only accessible in android 9.
I want to distinguish between users that have android 9 and can thereby use these features and users that are on 8.1 or lower for which I have to find an alternative solution.
Based on this information I want to call either the version with the features coming with android 9 or an alternative version that every smartphone can use.
My question now is, is it possible to create a project that contains android 9 "classes" but never get called when the device it is running on is 8.1 or lower.
Or is it not even possible to compile this project for a SDK version below android 9.
I am thankful for every answer.
Just check the Build version like this...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) ...

Target API - Will old devices still support deprecated features?

sorry if this question was already asked but I couldnt find anything.
Starting November 2018 all Android Apps need to target API lvl 26 or else you cant release any new updates. So I understand that when I target my App to API lvl 26 there will be features that wont work anymore. Like for example implicit broadcast receivers. Now my question. Will those old features that are deprecated in API lvl 26 stil work for devices that use older APIs? For example when someone uses a device that runs on API lvl 21. Will those devices still support those features even if my app targets API lvl 26?
I hope you understand what I mean.
Thanks in advance
Yes, though deprecated methods and functionalities should be avoided, devices that are running API level 21 will still support those features while your app is targeting any API > 21. This is true for any future requirement like this as well, until it is explicitly stated that the features will be removed.
Make sure that your app's min SDK is still at 21 or lower.

startDrag method Deprecated and unable to compile the program

startDrag(android.content.ClipData, android.view.View.DragShadowBuilder, java.lang.Object, int) is deprecated. How to solve this without losing compatibility to the older versions? Are there any alternatives? I'm learning android basics and while trying out a simple drag and drop exercise, I encountered this error.
According to Androids API reference startDrag() was deprecated in API level 24
Use startDragAndDrop() for newer platform versions.
And since Android API level 24 equals Android N you can use:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
view.startDragAndDrop(...);
} else {
view.startDrag(...);
}
startDrag was very recently deprecated - in API 24. So you could use startDragAndDrop instead and differentiate between versions.
What you could also say is preserving compatibility to lower versions. The thing is Drag&Drop was introduced in API 11. So you could try differentiating between versions:
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
//MyDragEventListener comes in here
}
Otherwise as said, there is no official Drag&Drop for < API 11. There is not much use of implementing it for Android below API 14 (or API 15 for that matter), because per Android Studio, there are only a handful of devices running below that version, i.e. only mere 2.3%.
If you still, insist on doing it, you could use a third party library such as Android-DragArea.
Hope this helps!

Why I still cannot use fragment when using Eclipse(Android)?

First, I've upgraded to API-21 including eclipse android toolkit and SDK.
I want to use the fragment feature and still want to support those 2.x phones
I know that I must use support library - v4.
But the problem is when I create an Android project, it always shows "Navigation Type "Scrollable Tabs + Swipe" requires a minimum SDK version of at least 11, and the current min version is 8".
How could I solve this tricky problem?
======================================
My settings:
Minimum required SDK: API 8
Target SDK: API 17
Compile With: API 17
======================================
Thanks!!
Eclipse's project templates make use of features that require a number of APIs (mostly ActionBar), which are not provided by the support library. While you can use Fragments, with the support library, you don't have the other features associated with the APIs.
You could still implement swipe/scroll tabs by yourself though. However, you will have to create them manually (and not using Eclipse's built-in project templates).
You will need to use android.support.v4.view.PagerTabStrip, android.support.v4.view.ViewPager and android.support.v4.app.Fragment. The documentation is pretty clear and should point you in the right direction.

Develop Android's application for all the versions

i'm developing an android application and i don't know how to make it compatible with all the versions. In eclipse i select only one API level, and in androidManifest i tried to put minSdk and MaxSdk covering all the version, but it crashes on some OS with different version.
How can i make it compatible with all the versions? Can you help me?
Do you really need to support all versions? Check out this chart, which the Android team updates monthly, and tells you what percentage of devices are running which Android versions. As you can see, 97% of devices are on Android 2.1+
I recommend supporting only Android 2.1+ (API level 7) if you can.
Android Platform Versions
I'd say that you'll make life really hard for yourself by attempting to make your application work on antiquated Android versions (and by that I mean 1.5 and 1.6). As Sky mentioned, only target Android 2.1 and above.
Can you please specify what exception is being thrown when you attempt to run the application on a different version of the OS?
Here's my application's definition in the manifest.
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10">
Defining it that way does not guarantee that your application will work on Froyo, Gingerbread and Gingerbread_MR1. Here's an example, I can't use requestSingleUpdate() from the LocationManager class in my application because it was only added in API level 9 (and I intend my application to work in API level 8!).
You need to ensure that you use functionality that is in API level 8 and below. Does that make sense?

Categories

Resources