0

I have a lot of data in json and i fetched it and get and set using getter setters and insert using below statement

long insertId = database.insert(StaticData.SCHOOL_TABLE_NAME, null,
                values);

but the query not inserted full record and my application crashed ,my no of rows are 40,000 .

2
  • Are you creating your database in internal storage of application? and can you show your crash report (logcat) Commented Sep 15, 2015 at 7:22
  • yes, i am inserting i in to my internal database Commented Sep 15, 2015 at 7:24

2 Answers 2

1

If you are inserting records in database on UI thread, I will suggest you to use AsyncTask for that task.

Too much work on UI thread might cause this problem.

Sign up to request clarification or add additional context in comments.

1 Comment

I have already use AsyncTask in my code to inserting data into database
0

According to you, the number of rows are huge so recommending that not to use AsyncTask, as it will not stick to Activity lifecycle. For Example, if the Activity dies, it doesn't mean AsyncTask dies as well,

1. But assume the rotation of the screen which occurred to restart Activity causes restart AsyncTask as well,

2. Once AsyncTask executed and back pressed and come back again into the same Activity before previously executed AsyncTask was not finished,

The behavior of both scenarios mentioned above may corrupt data or duplication of the data.

That's why I would Recommend using below approach,

Use IntentService and within the method named handleIntent() which executes in a worker thread so we don't need to worry about background task or blocked the main UI thread,

And another main advantage of using IntentService is, once operation of the insertion of the data into the SQLite Database will be finished, IntentService automatically self-kill that worker thread, so again no need to do manual stuff related to that,

And as it's running on a worker thread, there are very rare chances to worry about leaking from the memory.

Once insertion finished, we can do further operation related to UI using Handler and Messengers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.