title: Sqlite in Android 4.4 is deleted when closing app
body: <p>I've got a problem with sqlite in my application. The problem is: My sqlite with all data is vanished after closing app, reinstalling app in eclipse studio. I close app using back-arrow on my device or swipe out icon of this app from manager bar shown on the photo. When I add new position to my listView, it works fine but When I swipe out application from manager bar it destroyes my sqlite database and I lose everything. I store my list view in global object (extends Application). Problem is with this vanishing database. What is wrong here? I'm using Android 4.4 on tablet Samsung Galaxy Tab 4.</p>
  
  <p>PHOTO:</p>
  
  <p><img src="https://i.stack.imgur.com/wBgTG.png" alt="My app closing with &quot;swipe-out&quot; gesture"></p>
  
  <p>EDITED:</p>
  
  <p>My DBHelper Class</p>
  
  <pre><code>public class SqliteHelper extends SQLiteOpenHelper{
  
      public static final String TABLE_NAME = "gifs";
        public static final String NAME = "name";
        public static final String RATING = "rating";
        public static final String DATE = "date";
        public static final String URL = "url";
        public static final String COVERURL = "coverurl";
        public static final String MAIN_CONTENT_URL = "mainURL";
  
        public static final String  DATABASE_FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/storeUGif/";
  
  
        public static final String DATABASE_NAME = "items.db";
        private static final int DATABASE_VERSION = 1;
  
        private static final String DATABASE_CREATE = "create table " + TABLE_NAME + "(" + NAME + " text" + "," + RATING 
                + " int" + "," + URL + " text" + "," + DATE + " text" + "," + COVERURL + " text" + "," + MAIN_CONTENT_URL + " text" + ");";
  
      public SqliteHelper(Context context) {
  
          super(context,DATABASE_NAME, null, DATABASE_VERSION);
          //super(context,DATABASE_FILE_PATH + DATABASE_NAME, null, DATABASE_VERSION);
          if(GlobalApplicationState.DEBUG_MODE)
         System.out.println(DATABASE_FILE_PATH);
  
        }
  
      @Override
      public void onCreate(SQLiteDatabase database) {
  
           database.execSQL(DATABASE_CREATE);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
  
          database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
          onCreate(database);
  
      }
  
  
  
  
  }
  </code></pre>
  
  <p>Insert into method:</p>
  
  <pre><code>public void instertItemToDataBase(GifModel model)
      {
          if(!dataBaseManager.isOpen())
          {
              dataBaseManager.open();
          }
          if(!demotywatorBaseManager.isOpen())
          {
              demotywatorBaseManager.open();
          }
  
          if(model.getMainLinkToTheContent().contains("http://kwejk.pl"))
          {
              dataBaseManager.insertGifToDataBase(model);
  
              //dataBaseManager.close();
          }
          else if(model.getMainLinkToTheContent().contains("http://demotywatory.pl"))
          {
              demotywatorBaseManager.insertGifToDataBase(model);
              //demotywatorBaseManager.close();
          }
  
      }
  </code></pre>
  
  <p>And the last one:</p>
  
  <pre><code>public void insertGifToDataBase(GifModel newGif) {
  
          //System.out.println(newGif.getMainLinkToTheContent());
  
          ContentValues values = new ContentValues();
          values.put(SqliteHelper.NAME, newGif.getNameOfIteme());
          values.put(SqliteHelper.RATING, newGif.getRating());
          values.put(SqliteHelper.URL, newGif.getUrl());
          values.put(SqliteHelper.DATE, newGif.getAddedDate());
          values.put(SqliteHelper.COVERURL, newGif.getCoverUrl());
          values.put(SqliteHelper.MAIN_CONTENT_URL, newGif.getMainLinkToTheContent());
          database.beginTransaction();
          database.insert(SqliteHelper.TABLE_NAME, null, values);
          database.endTransaction();
  
      }
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <pre><code>public ArrayList&lt;GifModel&gt; getAllGifs() {
  
          ArrayList&lt;GifModel&gt; allGifs = new ArrayList&lt;GifModel&gt;();
  
          try
          {
              Cursor cursor = database.query(SqliteHelper.TABLE_NAME, allColumns, null, null, null, null, null);
              cursor.moveToFirst();  // Here exception shows up.
              while (!cursor.isAfterLast()) {
                  GifModel gif = cursorToNewGif(cursor);
                  allGifs.add(0,gif);
                  cursor.moveToNext();
              }
              // make sure to close the cursor
              cursor.close();
  
  
          }catch(Exception e)
          {
              //System.out.println(e.getMessage());
              e.getCause();
          }
  //      for(int i = 0; i &lt; allGifs.size(); i++)
  //      {
  //          System.out.println("CUrosr"+allGifs.get(i).toString());
  //      }
          return allGifs;
      }
  </code></pre>