Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store data in android for a long time?
    primarykey
    data
    text
    <p>I am trying to develop android application (first time), so I'm using SQLite to store data. But every time I run the application all data are null! I think the problem is when I run the application it recreates all the tables and they come as new empty tables!</p> <p>Can anyone help or give example how to check if the tables are already created, and if yes copy the data, if not create and that means it's a first time! How can I store data for a long time by using SQLite? If I cant what is the best way to store data?</p> <pre><code> //food private static final String food= "food"; //---- columns ----- private static final String fid = "fid"; private static final String fname= "fname"; private static final String category = "category"; private static final String quantity= "quantity"; private static final String unit= "unit"; private static final String carbs= "carbs"; //food private static final String DATABASE_CREATE_Food="CREATE TABLE " +food+" ("+fid + " INTEGER PRIMARY KEY AUTOINCREMENT , " +fname+ " TEXT NOT NULL, " +category+" TEXT Not NULL, " +quantity+" Double Not Null, " +carbs+" Integer NOT NULL, " +unit+" TEXT NOT NULL" +");"; public void onCreate(SQLiteDatabase database) { database.execSQL(DATABASE_CREATE_Food); } /** Called when the DATABASE_VERSION is changed to higher version */ @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(MyAppDB.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS" + food); onCreate(db); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload