So I'm working on a project like this http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ which let's me to display my database's values to my android application GUI.
I need to save the database values I need to the android internal storage so I can access it even if my application is not connected to the server. Any help?
Thank you
json file is generally placed in the app/ directory (at the root of the Android Studio app module).
If it is just an array you want to store and not store a name attribute to it. You can just store it as [1,2,3,4,5,6] . For example if you are storing it in an RDBMS, you may name the column as array and store the value as a JSON array. OR is wrapped in square brackets in case of arrays (ordered list of values).
JSON array can store string , number , boolean , object or other array inside JSON array. In JSON array, values must be separated by comma. Arrays in JSON are almost the same as arrays in JavaScript.
You can write whole json as string in shared prefernces, and then get it and parse it to display in GUI even when device is offline:
String str = json.toString();
SharedPreferences sharedPref = getSharedPreferences( "appData", Context.MODE_WORLD_WRITEABLE );
SharedPreferences.Editor prefEditor = getSharedPreferences( "appData", Context.MODE_WORLD_WRITEABLE ).edit();
prefEditor.putString( "json", str );
prefEditor.commit();
If you chose local sqlite database as your solution, I wrote a lightweight utility for saving your json into a sqlite.
checkout git repo here. https://github.com/wenchaojiang/JSQL
You only need one line of code.
new JSQLite(yourJsonString, yourDB).persist();
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With