0

In my app android:minSdkVersion="8", I get the following warning. Now my code is OK in API 17, could you tell me if my app can always work well in future Android version? Thanks!

the constructor simplecursoradapter(context, int, cursor, string[], int[]) is deprecated

4 Answers4

2

It depends on those guy, when they can remove it depends on them. Deprecated meaning? is here.

By reviewing the SimpleCursorAdapter doc, you will get two methods.. The one you are using SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) and another is SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) which added in API 11 after deprecation of previous.

The docs says

This constructor was deprecated in API level 11. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.

So You should modify your method as

if(android.os.Build.VERSION.SDK_INT >= 11) {
    //Call another constructor 
} else {
    //the constructor which you are calling
}
Community
  • 1
  • 1
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • if(android.os.Build.VERSION.SDK_INT >= 11) { adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, cur, cols, views,0); }else{ adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, cur, cols, views); } –  May 20 '13 at 14:02
  • I think the code above will cause error because adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, cur, cols, views,0); can work only API.sdk >=11 , now my app is android:minSdkVersion="8", but the code is OK in the app, why? Thanks! –  May 20 '13 at 14:05
1

Usually, when a feature is deprecated, they provide a new way to do the same thing. You should move to that new way of doing things.

Fustigador
  • 6,339
  • 12
  • 59
  • 115
0

You can use it for now, but it can disappear in the future, too.

devrique
  • 526
  • 4
  • 10
0

Deprecated functions are superseded with others that fulfil the same purpose in a better or more efficient way.

The answer to your question:

could you tell me if my app can always work well in future Android version?

Is almost certainly no - deprecated functions get phased out after a certain amount of time.

My advice is to use the replacement function as soon as you can implement it. There will be more benefits than just futureproofing.

Ed_
  • 18,798
  • 8
  • 45
  • 71