How do I know when the SQLite query is finished?

0

In my app I have a synchronization method, this method downloads multiple entries from my webservice and inserts them into the local SQLite database through a for loop. I need to know when the SQLite insert is finished so I can display a window stating that the operation was successful.

However, there are many records, more than 500, and SQLite ends up taking a few seconds to insert into the database, and with those seconds that take, my code already makes the AlerDialog call, informing the result of the operation.

How can I make AlertDialog only called when the SQLite insert is completely finished?

Retrofit call that downloads the registrations

final CadastroApi cadastroApi = retrofit.create(CadastroApi.class);

Call<List<Cadastro>> callCadastro = cadastroApi.getCadastro(token);
    callCadastro.enqueue(new Callback<List<Cadastro>>() {
        @Override
         public void onResponse(Response<List<Cadastro>> response, Retrofit retrofit) {

            List<Cadastro> cadastroList = response.body();

            if (cadastroList != null) {

                try {

                    DBHelper dbHelper = new DBHelper(TokenActivity.this, token);
                    SQLiteDatabase conn = dbHelper.getWritableDatabase();
                    RepositorioCadastro repositorioCadastro = new RepositorioCadastro(conn);

                    // Insere cada item da lista no Banco de dados
                        for (Cadastro c : cadastroList) {

                            repositorioCadastro.inserirCadastro(c);

                            Log.i("ACTTOKEN", "Cadastro inserido ID: " + c.getId());

                        }

                } catch (SQLiteException e) {
                 Log.i("ACTTOKEN", "Erro ao inserir Cadastro(s) no banco de dados local: " + e.getMessage());
                }

}
    
asked by anonymous 13.01.2016 / 18:46

0 answers