Saturday, October 29, 2011

Android Developer Tutorial is Deprecated?

I've dabbled in Android development for some time having created a few homebrew apps for my personal usage including a small password en/decrypter. But I'm finally taking the plunge into pro development to expand my skill set. As I was going through the Notepad Tutorial on the Android SDK I noticed something strange in the final step for Notepad Exercise 1.

The code given in the Android Tutorial is


private void fillData() {
        // Get all of the notes from the database and create the item list
        Cursor c = mDbHelper.fetchAllNotes();
        startManagingCursor(c);

        String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
        int[] to = new int[] { R.id.text1 };
        
        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
        setListAdapter(notes);
    }

But when you check the documentation you find this.

public SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to)

This constructor is deprecated.
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.

The documentation for the LoaderManager isn't exactly the easiest thing to understand for someone who really is on their first day of Android (even if they have a decent enough a Java background) so maybe it would have been better to at least include a Notepadv4 exercise to cover this? Anyway I'm going to redo the Notepad exercise once I'm done up to v3 and I'll post the redone version using a LoaderManager.

edit - Upon checking again I realized the SDK version this applies to is actually one that is higher up than what I am using currently. Version 11 to be precise. Regardless of that they really need to update the tutorial. Maybe we'll see a tutorial fragmentation now.

No comments:

Post a Comment