API Level 11 min is 9, what can I do to fix this

237 Views Asked by At

One of my classes has many errors because API level 11 (min is 9) is it better to fix it or change min. If so how do I fix it or how do I change min Im very new to this, also what is a good source to learn from with new-ish code

package com.ramos.science;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;

public class Prefs extends PreferenceActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getFragmentManager().beginTransaction().replace(android.R.id.content, new       MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(com.ramos.science.R.xml.prefs);
}

}
}
4

There are 4 best solutions below

3
On

modify AndroidManifest.xml file

add

 <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17"/>
1
On

It really just depends on what you want and who you are targeting. Since Fragment was introduced in API 11, if you want to use them then you should make your minimum >= 11. If you look at the DashBoard Docs you can see that the majority of devices which download apps from the Play Store are Gingerbread (API 9). If you want to reach the broadest amount of people then you may not want to use Fragments but if you want to program for the future then I would suggest using a minimum of 11.

It really kind of depends on who you are targeting. But ICS has gained a lot of ground in the last 6 months or so. My recommendation would be to program for those newer devices because their slice is only going to get bigger. Unless, of course, you know that a lot of your users will have older devices

Supporting different versions

0
On

Inside of class you can use Android annotations like so:

@TargetApi(11)
public void functionName() {
   ...
}
0
On

In additional to what codeMagic has explained. This is an add-on resources for what you need: What API level should I target.


Besides I have difficulties when I first kick-started android, here's some really good android books for beginner:

  1. Pro Android 3 (Android developer would keep this in their bookshelf)
  2. Head First Android Development (It guides you by example)
  3. Learning Android (Perfect book to master your fundamentals)

To master the best android practices, learn from his code: yuriykulikov/AlarmClock

After all, I hoped it helps :) Good luck.