ContentProvider without SQL

I have two pieces of data that need to be retrieved from external applications and stored. According to the documentation, ContentProviders is the only possible way, but it also mentions external storage. ContentProviders implement a "database-like" interface, and using a database would be extremely unnecessary for two pieces of data. I would rather save them to a file, but using ContentProvider by implementing abstract methods is problematic because the methods are structured as database queries.

I know that there is nothing to indicate that ContentProviders should use the database under the data store, but is there any other way to store the minimum amount of data that should be transferred to the file system?

+7
source share
2 answers

I just used MatrixCursor to solve this exact problem. Take a look at this.

Edit: Sorry, I just looked at a question when I answered it. ContentProvider is the only way applications can share data. Application actions can use SharedPreferences for smaller data with the addition of a save.

Edit v2: here is the function that I used to populate the MatrixCursor for the request function of my ContentProvider. I use the predefined VIEW that I created, which returns a set of different values, and this sets the cursor with _ids, which I can pass to my ExpandableListView.

 private Cursor getFactions() { MatrixCursor mc = new MatrixCursor(Model.Faction.PROJECTION); SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = db.query(MODELFACTION_TABLE_NAME, new String[] { Model.Faction.FACTION }, null, null, null, null, Model.Faction.FACTION + " ASC"); c.moveToFirst(); do { mc.addRow(new Object[] { c.getPosition(), c.getString(c.getColumnIndex(Model.Faction.FACTION))}); } while (c.moveToNext() && ! c.isAfterLast()); c.close(); db.close(); return mc; } 
+6
source

The SharedPreferences class provides a general structure that allows you to store and retrieve constant key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans , float , ints , longs and <strong> strings. This data will be saved in user sessions (even if your application is killed)

Useful links:

http://developer.android.com/reference/android/content/SharedPreferences.html

http://developer.android.com/guide/topics/data/data-storage.html

+1
source

All Articles