android - ContentProvider database variables, where to put them? -


consider:

public static final string note_id = "_id"; public static final string title = "title"; public static final string text = "text"; 

3 columns in sqlite database shown above used in content provider, put these in code below? best place?

and should put in noteitems class extends basecolumns?

a little confused on put what.

public class providerexample extends contentprovider {  private static final string database_name = "notes.db"; private static final int database_version = 1; private static final string table_name = "notes"; public static final string authority = "package   com.example.contentproviderexample.providerexample";  public static final urimatcher surimatcher;  private static final int notes = 1;  private static final int notes_id = 2;  public static final uri content_uri = uri.parse("content://"         + authority + "/notes");       static final string single_record = "vnd.android.cursor.item/vnd.example.providerexample";      static final string multiple_records = "vnd.android.cursor.dir/vnd.example.providerexample";   static {         surimatcher = new urimatcher(urimatcher.no_match);         surimatcher.adduri(authority, table_name, notes);         surimatcher.adduri(authority, table_name + "/#", notes_id);     }      public static interface noteitems extends basecolumns { }      private static class databasehelper extends sqliteopenhelper{     databasehelper(context context)     {     super(context, database_name, null, database_version);     }      @override     public void oncreate(sqlitedatabase db) {}      @override     public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {         // todo auto-generated method stub     } } // databasehelper 

edit:

i narrowed down choice. looks 2 places best put code. 1 inside providerexample extends contentprovider class along other variables, , other position inside databasehelper extends sqliteopenhelper class, both possible, don't know of 2 places more correct. have found examples of both ways being used.

3 columns in sqlite database shown above used in content provider, put these in code below? best place?

and should put in noteitems class extends basecolumns?

this aren't questions answered. put them @ bottom of class , doubt you.

when using contentprovider idea use contract class/interface in put provider related constants easy access/change , (possible) public release(if allow provider used other apps). part covered in guide providers available on android developers site recommend read.

i move notesitems interface in own file , put constants in it(at least ones mention) , access them using notesitems._id etc


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -