The BaseColumns interface provides names for the very common _ID and _COUNT .
Using common names allows the Android platform (and developers) to access any data item, regardless of the general structure (i.e. other columns without an identifier) ββin a unified way. Defining constants for commonly used strings in an interface / class avoids duplication and typos throughout the code.
Using a column named _ID (constant BaseColumns._ID ) is required by CursorAdapter , the implementation of ContentProvider and in other places where you pass Cursor to the Android platform to do something for you. For example, the ListView adapter uses the _ID column to give you a unique identifier for the list item clicked in OnItemClickListener.onItemClick() , without having to explicitly indicate that your identifier column each time.
Regardless of whether interfaces consisting only of constants or reference with their full name are implemented, i.e. BaseColumns._ID . I personally prefer the latter because it is more obvious where the _ID comes from, and the former seems to be an abuse of inheritance.
Philipp Reichart Oct 26 '11 at 8:56 2011-10-26 08:56
source share