Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of FeedReaderContract and how to define inner class in OpenHelper Class [closed]

Tags:

android

sqlite

I am learning SQLite in android. For SQLite I am reffering developer.android.com. But I got some Confusion while reading the code. They wrote FeedReaderContract constructor to prevent instantiating the FeedReaderContract class but they don't define FeedReaderContract class anywhere and the relation between FeedReaderContract and FeedEntry.

Here's link which I am referring to. I provide code. How can I define inner class in openhelper class. Could anybody suggest me the good way?.

For example, this snippet defines the table name and column names for a single table:

public static abstract class FeedEntry implements BaseColumns 
{
    public static final String TABLE_NAME = "entry";
    public static final String COLUMN_NAME_ENTRY_ID = "entryid";
    public static final String COLUMN_NAME_TITLE = "title";
    public static final String COLUMN_NAME_SUBTITLE = "subtitle";
    ...
}

To prevent someone from accidentally instantiating the contract class, give it an empty constructor.

 //Prevents the FeedReaderContract class from being instantiated.
private FeedReaderContract() {}
like image 981
nilesh wani Avatar asked Oct 05 '22 08:10

nilesh wani


1 Answers

I understand as:

public static class FeedReaderContract{

    // Prevents the FeedReaderContract class from being instantiated.
    private FeedReaderContract() {} 

    //The FeedEntry table definition
    public static abstract class FeedEntry implements BaseColumns {
        public static final String TABLE_NAME = "entry";
        public static final String COLUMN_NAME_ENTRY_ID = "entryid";
        public static final String COLUMN_NAME_TITLE = "title";
        public static final String COLUMN_NAME_SUBTITLE = "subtitle";
        ...
    }

    //more tables definition
}

So you can't instatiate the contract but can access all the inner classes Constants. Like the example line:

private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + FeedReaderContract.FeedEntry.TABLE_NAME + " (" +
FeedReaderContract.FeedEntry._ID + " INTEGER PRIMARY KEY," //continues

Access the FeedEntry constants (TABLE_NAME and _ID) of the inner class in FeedReaderContract class.

Hope it helps.

like image 129
sabadow Avatar answered Oct 10 '22 03:10

sabadow