2

Im using the ActiveAndroid library and I have read the entire information (very minimalist and insufficient unfortunately) There is no mention whether the .save() operation is executed syncrhonously.

If it is asynchronous, how do I "listen" for it to end before proceeding?

http://www.activeandroid.com/ - this is the documentation I read

Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180

1 Answers1

4

If you have a look at the source code of the Model class, you'll see that the save method does not do any thread handling:

public final Long save() {
    final SQLiteDatabase db = Cache.openDatabase();
    final ContentValues values = new ContentValues();

    for (Field field : mTableInfo.getFields()) {
        /* ... */
    }

    if (mId == null) {
        mId = db.insert(mTableInfo.getTableName(), null, values);
    }
    else {
        db.update(mTableInfo.getTableName(), values, idName+"=" + mId, null);
    }

    Cache.getContext().getContentResolver()
            .notifyChange(ContentProvider.createUri(mTableInfo.getType(), mId), null);
    return mId;
}

Saving thus occurs synchronously.

nhaarman
  • 98,571
  • 55
  • 246
  • 278
  • I looked at that but I considered the possibility that maybe the deferring to another thread might happen somewhere else at a higher level – Kaloyan Roussev Mar 28 '15 at 14:38
  • What should we do when we want to use `.save()` and `Update()` in a separate thread other than of main thread. Because it shows ANR on `.save()` and `Update()` for many records. – hasnain_ahmad May 01 '18 at 19:25