mardi 30 juin 2015

How to write Android Async task for database inserting

I'm new to android. I need to insert huge data stack to database at first run of my app (min number of lines copied to here). This database insertion will take few minuets to complete. I want to add progress bar showing in this time. I looked in the internet and copied some codes, but I never completed this task correctly. Can you help me to do this database insertion through Async task. I used database open helper to insert data. Tank you.

buttonInitiate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {               

                dbConn = new DatabaseConnect(getApplicationContext());              

                dbConn.insertContact("1","g1", "m1", "apostolic  nunciature  in  sri  lanka ", "112582554","112597685", "", "112580906");
                dbConn.insertContact("1","g1", "m1", "Cardinal - Archbishop of Colombo His Eminence  Malcolm Cardinal Ranjith", "112695471","112695472", "112695473", "112692009");
                dbConn.insertContact("1","g1", "m1", "Conference  of  major  religious  superiors  sri lanka, Executive Secretary Sister Laetitia Coorey RGS", "766594466","713452929", "", "");
                dbConn.insertContact("1","g1", "bh", "Anuradhapura", "252222503","252234332", "", "252234901");
                dbConn.insertContact("1","g1", "bh", "Badulla", "552229241","552222867", "552222079", "552229241");
                dbConn.insertContact("1","g1", "bh", "Batticaloa", "652227642","652222723", "", "652224667");
                dbConn.insertContact("1","g1", "bh", "Chilaw", "322220625","322223377", "322222332", "322223233");
                dbConn.insertContact("1","g1", "bh", "Galle", "912234256","912223318", "", "914385602");
                dbConn.insertContact("1","g1", "bh", "Jaffna", "212222649","212222161", "", "212229953");
                dbConn.insertContact("1","g1", "bh", "Kandy", "814471601","814471602", "812222300", "812222300");
                dbConn.insertContact("1","g1", "bh", "Kurunegala", "372222854","372224935", "", "");
                dbConn.insertContact("1","g1", "bh", "Mannar", "232222503","232222710", "", "232222709");
                dbConn.insertContact("1","g1", "bh", "Ratnapura", "362232368","362232369", "362232370", "");
                dbConn.insertContact("1","g1", "bh", "Trincomalee", "262222677","262050546", "", "262222238");

                dbConn.insertKey("g1", "General Information");
                dbConn.insertKey("m1", "Main Information");
                dbConn.insertKey("bh", "Bishop`s Houses");
                dbConn.insertKey("nda", "National Directors / Animators");
                dbConn.insertKey("nc", "National Chaplains");
                dbConn.insertKey("cmr", "Congregations of Men Religious");
                dbConn.insertKey("cwr", "Congregations of Women Religious");
                dbConn.insertKey("ccwr", "Contemplative Congregations of Women Religious");


                buttonGo.setEnabled(true);

            }

        });

Aucun commentaire:

Enregistrer un commentaire