Good practices with Android comic book

Asked

Viewed 22 times

2

What would be the best practices in relation to sqlite on Android? I use a single db Contract for all tables (each table a class within the main class Contract)?

public final class FeedReaderContract {
    // To prevent someone from accidentally instantiating the contract class,
    // make the constructor private.
    private FeedReaderContract() {}

    /* Inner class that defines the table contents */
    public static class FeedEntry implements BaseColumns {
        public static final String TABLE_NAME = "entry";
        public static final String COLUMN_NAME_TITLE = "title";
        public static final String COLUMN_NAME_SUBTITLE = "subtitle";
    }

    public static class OutraTabela implements BaseColumns {
     ....
    }
}

Or I create a Contract class for each table?

1 answer

1


The way you’re doing it is great. I believe you should also implement a Contentprovider, so specifying the access Urls for each table in the Contract is a good one.

All you need is a contract file. If you have many tables even, maybe you can separate them into several files by grouping the tables by subject.

This Google training gives great direction on the subject:

https://br.udacity.com/course/android-basics-data-storage--ud845/

  • in the case I have 12 tables (which are many), I was confused, because in the google documentations, it does not say if I should put all tables in the same class Tract, I thought so.. There are 12 tables, IE, 12 files, would not get messy?

  • There is no direction for this in practice. 12 tables is little, because you are only creating constants in the classes and a few methods. I would put everything in one. But it is to the taste of the customer, rs, the important is also not to "organize" too much and make it difficult to read.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.