AsyncTask and function onUpdate

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

AsyncTask and function onUpdate

Postby kurdak » Thu Jun 14, 2012 11:04 pm

This time, a more complicated example, namely, I mean updating the database after changing the version. As I move update feature on statistics, to keep them for you and it is obvious that it takes a little time, so I decided to move it to AsyncTask.

So it looks like my class:
Code: Select all
public class DataBaseHelper extends SQLiteOpenHelper {

/**
  * some code
**/

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (newVersion > oldVersion) {
            Log.e("TAG", "New database version exists for upgrade.");

            new UpdateDB().execute(db);

        }

    }

    public class UpdateDB extends AsyncTask<SQLiteDatabase, Void, Void> {

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(SQLiteDatabase... params) {
            try {
                Log.e("TAG", "Copying database...");
                ArrayList<Statistic> statistics = DataBaseHelper
                        .allStatistics(params[0]);
                ArrayList<Egzam> exams = DataBaseHelper.loadExams(params[0]);
                copyDataBase();
                params[0].delete(DATABASE_TABLE_EXAMS, null, null);
                for (int i = 0; statistics.size() > i; i++) {
                    addStatistic(statistics.get(i).getId_pytania(),
                            statistics.get(i).getNumberOfSolutions(), statistics
                                    .get(i).getNumberOfCorrect(), statistics
                                    .get(i).getNumberWrong(), params[0]);
                }
                for (int j = 0; exams.size() > j; j++) {
                    addExams(exams.get(j).getCorrect(),
                            exams.get(j).getTime(), params[0]);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            // TODO Auto-generated method stub
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
        }

    }
}


I suspect that the need to add here onPostExecuteListener but I have no idea how to do it. I never used to use, also very please help. How do I add onPostExecuteListener? Please for example.
kurdak
Freshman
Freshman
 
Posts: 8
Joined: Thu Oct 20, 2011 3:44 pm
Location: Poland

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests