i want to add data in 3 tables in one database from 3 AsyncTask object. because the AsyncTask objects may run or finish at the same time and i'm adding data in my database in onPostExecute() , i want to know is it possible to do such a thing or not ? thanx
Asked
Active
Viewed 33 times
0
-
1It sounds as if the `executeOnExecutor()` method in the `AsyncTask` class would be relevant here: http://developer.android.com/reference/android/os/AsyncTask.html#executeOnExecutor(java.util.concurrent.Executor, Params...) - However, as I don't have any personal experience using it I'll leave this as a comment in case someone else can answer more fully. – PPartisan Oct 03 '15 at 06:11
1 Answers
1
Android SQLiteOpenHelper
is synchronized by default. all you need to do is make your DB helper singleton and you will not face any problem.
Read this for more info on singleton db helper.

Community
- 1
- 1

Rahul Tiwari
- 6,851
- 3
- 49
- 78
-
ty , you mean if i use simple SQLiteDatabase objects and use them for insert and select , it may cause problems ? – Pirisok Oct 03 '15 at 06:23
-
Worth keeping in mind that [Android Design Patterns](http://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html "synchronized getInstance()") also recommend making the `getInstance()` method `synchronized` for this reason. – PPartisan Oct 03 '15 at 06:29
-
i already write my all codes with SQLiteDatabase , is there a better way to i use this class rather than SQLiteOpenHelper ? – Pirisok Oct 03 '15 at 06:30
-
@Pirisok `SqliteOpenHelper` is [officially recommended](http://developer.android.com/guide/topics/data/data-storage.html#db) way – Rahul Tiwari Oct 03 '15 at 06:36