0

I'm trying to develop an android app that takes some data from a txt file (which is about 7 million lines long close to 32 MB) processes it according to some conditions places them in an SQL database and retrieves them. As far as the database is concerned it works well since I have tested it in alternative way, but for some reason it has a hard time dealing with the file, and my code becomes very unresponsive. What is an efficient way of doing this?

user2268636
  • 11
  • 1
  • 5

2 Answers2

0

If time-consuming part is the file input may be using an async task to to do the work (read the file and prepare the DB) in the background and then notify the user when it's done. This way the user can keep using the app. Here are some links:

AsyncTask

AsyncTask example

According to the documentation the asyncTask should only be used for not so long operations (a few seconds only):

AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent pacakge such as Executor, ThreadPoolExecutor and FutureTask.

Community
  • 1
  • 1
fersarr
  • 3,399
  • 3
  • 28
  • 35
0
  1. run the code in separate thread (async task)
  2. instead of loading whole file at once, process it line by line. this would help you to reduce memory consumption
user1991679
  • 2,109
  • 1
  • 23
  • 19