Android DBFlow does not save objects


I have a database like this:

@Database(name = QuestionDatabase.NAME, version = QuestionDatabase.VERSION)
public class QuestionDatabase {

    public static final String NAME = "QuestionDatabase"; // we will add the .db extension

    public static final int VERSION = 1;

and a table like this:

@Table(database = QuestionDatabase.class)
public class Question extends BaseModel {
    public int localID;
    public int Id;
    public String Answer;
    public String ImageURL;
    public boolean IsFavorite;
    public boolean IsSolved;

and an asynctask to retrive data from server:

public class QuestionRetriever extends AsyncTask<Integer, Void, Integer> {

    private Activity callerActivity;
    private QuestionAdapter questionsAdapter;
    private List<Question> callerQuestions;

    private Integer pageSize = 10;

    public QuestionRetriever(Activity callerActivity, QuestionAdapter questionsAdapter, List<Question> questions){
        this.callerActivity = callerActivity;
        this.questionsAdapter = questionsAdapter;
        this.callerQuestions = questions;

    protected Integer doInBackground(Integer... pageNumbers) {
        Retrofit retrofit = new Retrofit.Builder()

        QuestionWebService service = retrofit.create(QuestionWebService.class);

        Call<List<Question>> call = service.getQuestionsPaged(pageNumbers[0].toString(), pageSize.toString());

        try {
            Response<List<Question>> excecuted = call.execute();
            List<Question> questions = excecuted.body();
            callerActivity.runOnUiThread(new Runnable() {
                public void run() {

            //Get TotalQuestionCount if not yet
            if (((StatefulApplication) callerActivity.getApplication()).getQuestionCount() == -1){
                Call<Integer> call2 = service.getQuestionsSize();
                try {
                    ((StatefulApplication) callerActivity.getApplication()).setQuestionCount(call2.execute().body());
                } catch (IOException e) {
        } catch (IOException e) {
        catch (Exception e){

        return 1;

    protected void onPreExecute() {

        //TODO: show loader

    protected void onPostExecute(Integer result) {

        //TODO: hide loader

as you see every thing seems ok and eve after running FastStoreModelTransaction nothing wrong happens. no errors.

the init job is done in splash screen activity like this:

private void initializeEveryRun() {
        //Initializing DBFlow
        //DBFlow needs an instance of Context in order to use it for a few features such as reading from assets, content observing, and generating ContentProvider.
        //Initialize in your Application subclass. You can also initialize it from other Context but we always grab the Application Context (this is done only once).
        FlowManager.init(new FlowConfig.Builder(getApplicationContext()).build());

any idea about what should cause this problem or any solution to try? TG.

Show source
| android   | save   | dbflow   2016-12-29 11:12 2 Answers

Answers to Android DBFlow does not save objects ( 2 )

  1. 2016-12-29 13:12

    I found the answer!!!

    As you see in the model, the Id is the identifier of the object retrieved from server and LocalId is the auto-increment identifier that is stored locally. This was the problem. I've used the Id field as Primary Key and added a field named OnlineId for server side identifer and everything is ok now.

    Is this a bug or I was using that wrong?


  2. 2017-01-05 19:01

    This is not execute transaction, it's just transaction creation.

    As you can see it this test DBFlow - FastModelTest.kt.

    FastStoreModelTransaction .insertBuilder(FlowManager.getModelAdapter(Question.class)) .addAll(questions) .build();

    You must execute your transaction like this :

    Otherwise, if you already had a DatabaseWrapper instance you can do <<YourTransaction>>.excute(<<YourDatabaseWrapper>>);.

Leave a reply to - Android DBFlow does not save objects

◀ Go back