0

Example:

Let assume we have one method ondiscover() its call per mili second and find the data.

and save the data in one array temp_array and push the data in Local DB callThreadToSavedataInLocalDB()

the callThreadToSavedataInLocalDB() is slower than ondiscover() after some time my temp_array is full and app is crash. How to handle this problem.

how to increase the speed of data saving or if you have any other idea please suggest me.

i am giving you high level code idea how its work. ArrayList mapList; ArrayList tempList;

we have a method

ondiscover(arraylist arg)
{

tempList = addAll(arg)    // make clone the arg  list

if(tempList != null){
mapList = tempList;

tempList.clear();


if(not alive){

 callThreadToSavedataInLocalDB(mapList); // Thread to save data in Sqlite

}
}
}

in Above code ondiscover called in very millisecond and callThreadToSavedataInLocalDB may take time to store data in local DB so at some time tempList have more data that may be crash the application.

2 Answers2

0

For inserting the large data in Sqlite database, we can use transaction functionality.

Below link will help you:

Android Database Transaction

Community
  • 1
  • 1
Mavya Soni
  • 932
  • 7
  • 15
0

If you use transactions you can improve performances.

Basically you need to

1 - Open the transaction
2 - loop over element to add
2.1 - Add element
3 - Close the transaction

Additionally you can also use a query like the following:

INSERT INTO 'table'
      SELECT 'a' AS 'column1', 'b' AS 'column2'
      UNION ALL SELECT 'c', 'd'
      UNION ALL SELECT 'e', 'f'

This is the query equivalent to the standard sql

INSERT INTO table
values
('a', 'b'),
('c', 'd'),
('e', 'f'),
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56