In the structure of your tables, there is no use whatsoever and you can simply define public static final String _ID = "_id";
But why is this constant in Android ?
This constant is for you to have the correct value of the ID
field when you are filtering something from the Android database.
Example how to filter call logs.
Cursor c = contentResolver.query(CallLog.Calls.CONTENT_URI,
new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION,
CallLog.Calls.NUMBER, BaseColumns._ID },
BaseColumns._ID + " = ?",
new String[] { "1" },
CallLog.Calls.NUMBER + " asc");
Note that in the above code we use BaseColumns._ID
. In these cases it is necessary to use this way, because Android can change this value of the field ID
in the future and thus our code stays updated.
If we used _id
(as in the example below) our code would no longer work.
Cursor c = contentResolver.query(CallLog.Calls.CONTENT_URI,
new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION,
CallLog.Calls.NUMBER, "_id" },
"_id = ?",
new String[] { "1" },
CallLog.Calls.NUMBER + " asc");
So, when your data structure , use whatever form you prefer; When using the Android data structure, use the available constants.