Waves
Waves

Reputation: 1003

Using large databases in Android Apps

I have an Android App that uses an SQLite database. The problem is that the database has gotten to be quite large (41.6 MB) and I'm starting to wonder if I am correctly loading it into the app.

Right now what I'm doing is in the onCreate() method of my app's splash screen I'm opening the database, querying it, saving the data as objects, then closing the database. It takes a noticeable amount of time on a cold launch. Ideally I want to do all of this on the first launch and save the data somewhere on the device to speed up future launches. Is there a way I can do that?

Upvotes: 1

Views: 59

Answers (1)

Andrew Indayang
Andrew Indayang

Reputation: 172

I have same problem before.Probably thats the same case. Mine one because I pinging too many times of the Backend API and there is one more problem where you insert into your Object. probably when you insert it, The data that should just insert once, you insert it too many times on the for loop if there are many object that you are going to insert. Probably you can put your code when inserting it. lots of dev doesn't care about that but actually thats really annoying to user.

in my case because of this :

  manager.removeAllStop();
  manager.removeAllUpload(); //--> remove the data before insert the new one

  for (Stop stop : SomeStopsList) { //--> when I want to loop through and want to add it to other object

      **manager.insertAppTourStopList(appTourStopList);** //--> PROBLEM HERE !!!! THIS COULD BE OUTSIDE FROM THE LIST BECAUSE YOU WANT THIS TO BE ADDED ONCE ONLY

      ArrayList<Upload> uploadList = new ArrayList<Upload>(); // --> new object
      for (Upload uploadData : stopList.uploads) { //--> get the list and loop 
          Upload upload = new Upload(); //--> create new object
          upload.setStopId(stopList.getId()); //--> insert it
     }
  }

Upvotes: 1

Related Questions