0

Okay, this is more of a speed issue. The problem is that I am fetching three fields from varied sources like Contacts, Facebook and Google plus. The three fields are a date, name and a contact image URi. The logic is such that each of the sources writes to a File, Contacts -- to file, Facebook - append to same file, Google Plus - append to same file. This operation is pretty fast and takes the normal time to execute. This creates my original Data source. Then from this file I fetch each record (Row with three fields) individually and do some calculations and write data pertaining to each record into three different database tables. While as this works pretty fast on a Quad Core phone, the process is too slow on a dual core phone. It takes around ten minutes to process 150 records on a dual core, takle four minutes to process 150 records on Quad core. I am perplexed as in how to increase the speed? Should I drop the idea of making a file as my original Data Source and instead switch to a Database table? What would be the fastest?

The code is as follows:

    private class MagicCall extends AsyncTask<Void, String, String> {

        int years; 
        long secon; 
        long min; 
        int hours;
        int mon; 
        int days;
        int weeks;
        String CONTACT_ID,CONTACT_NAME,CONTACT_IMAGE_URI; 

        ProgressDialog Asycdialog = new ProgressDialog(LoaderClass.this);

        @Override
        protected void onPreExecute() {
            boolean DIALOG_SHOW = true;
            try{
                BufferedReader br = null; 
                if(FLAG ==1){
                    br = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/fileone.txt"));    
                }else{
                    br = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/output.txt"));  
                }
                if (br.readLine() == null) {
                    Toast.makeText(getApplicationContext(),"There are no contacts with Birthday details, try syncing with Facebook and/or Google", Toast.LENGTH_LONG).show(); 
                    DIALOG_SHOW = false; 
                }
            }catch(Exception e){
                System.out.println(e);
            }
            if(DIALOG_SHOW){
                //Init the LoaderDialog 
                Asycdialog.setMessage("Working");
                Asycdialog.getWindow().setGravity(Gravity.CENTER_VERTICAL);
                Asycdialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
                Asycdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                Asycdialog.setCancelable(false);
                //Dialog Show
                Asycdialog.show();

            }

            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            Editor editor = prefs.edit();
            editor.putBoolean("async", true);
            editor.commit();
            super.onPreExecute();
        }

        protected void onPostExecute(String result) {
            // hide the dialog

            DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy, h:mm a");
            String date = df.format(Calendar.getInstance().getTime());
            SharedPreferences prefsx = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            Editor editorx = prefsx.edit();
            editorx.putString("refresh", date);
            editorx.commit();



            dbHelper.close();
            Asycdialog.dismiss();
            startActivity(new Intent(LoaderClass.this, MainActivity.class));
            finish();

            super.onPostExecute(result);
        }

        @Override
        protected String doInBackground(Void... args) {

            dbHelper = new DBAdapter(getApplicationContext());
            dbHelper.open(); 
            int i=0;
            int lines = 0;
            //  int prog = fetchAdhoc();
            String progress = null; 
            String dateToInsert;
            try{
                BufferedReader reader;
                if(FLAG ==1){
                    reader = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/fileone.txt"));
                }else{
                    reader = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/output.txt"));
                }
                while (reader.readLine() != null) lines++;
                reader.close();
            }catch(Exception e){

            }

            Cursor c = dbHelper.fetchAdhoc(); 
            ADHOC_COUNT = (c.getCount());
            lines=lines+ADHOC_COUNT;
            dbHelper.NotificationDrop(); 
            if (c.moveToFirst()) {
                do {
                    try{
                        String name = c.getString(c.getColumnIndexOrThrow("Name"));
                        String displayBirthday = c.getString(c.getColumnIndexOrThrow("DOB"));
                        String imageData = c.getString(c.getColumnIndexOrThrow("ImageData"));
                        String primaryAdhoc = c.getString(c.getColumnIndexOrThrow("_id"));
                        //CONTACT_ID,CONTACT_NAME,CONTACT_IMAGE_URI

                        CONTACT_ID = primaryAdhoc;
                        CONTACT_NAME = toTitleCase(name); 
                        CONTACT_IMAGE_URI = imageData; 
                        dateToInsert = displayBirthday; 

                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                        Date date = format.parse(dateToInsert);
                        java.sql.Date dx = new java.sql.Date(date.getTime());
                        Date key = dx;

                        years = getDiffYear(key);               // For years elapsed
                        secon = seconds(key);                   // for seconds elapsed
                        min = seconds(key) / 60;                // For minutes elapsed
                        hours = (int) (seconds(key) / 60) / 60; // For hours elapsed
                        mon = months(String.valueOf(key));      // for months elapsed

                        days = daysElapsed(key);                // Days elapsed
                        weeks = daysElapsed(key) / 7;           // For weeks


                        System.out.println(lines);
                        progress = ("" + (CONTACT_NAME) + "\n"+ i + " of " + lines + " Contacts");
                        dbHelper.insert(dateToInsert, CONTACT_NAME, String.valueOf(days), String.valueOf(hours), CONTACT_IMAGE_URI, String.valueOf(min),String.valueOf(mon), String.valueOf(secon), CONTACT_ID, String.valueOf(weeks), String.valueOf(years));

                        int PRIMARY_ID = dbHelper.getPrimaryId(); // Fetch the PrimaryId (_id) of the above inserted row, its the Foreign key for Notification and SpecialNotifications Table. 
                        String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); // Same as above, but fetches the Name field of the last inserted row. 



                        //=========================================================================
                        //**Database Insertions Notifications Table/ SpecialNotifications Table**
                        //=========================================================================



                        //=======================================================================================//
                        //Regular intervals DB Insertions: 
                        //======================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //======================================================================================//

                        //==============================
                        //For Months 
                        //==============================
                        intCal.monthsNotify(mon, dateToInsert);
                        int monSpecial =  intCal.getMonthRegular(); 
                        Date dateMonReg = intCal.getMonRegDate(); 


                        dbHelper.insertNotifications(1, convertDate(dateMonReg), 0, monSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Weeks 
                        //===============================
                        intCal.weeksToNotify(weeks,dateToInsert); 
                        int weekSpecial = intCal.getWeekRegular();
                        Date dateWeekReg =intCal.getWeekRegDate(); 

                        dbHelper.insertNotifications(2, convertDate(dateWeekReg), 0, weekSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Days
                        //===============================
                        intCal.daysToNotify(days, dateToInsert); 
                        int daysSpecial= intCal.getDaysRegular();  
                        Date dateDaysReg = intCal.getDaysRegDate(); 

                        dbHelper.insertNotifications(3, convertDate(dateDaysReg), 0, daysSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For minutes
                        //===============================
                        intCal.minutesToNotify(min,dateToInsert);
                        long minutesSpecial= intCal.getMinutesRegular();
                        Date dateMinsReg = intCal.getMinutesRegDate(); 

                        dbHelper.insertNotifications(4, convertDate(dateMinsReg), 0,(int) minutesSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //==============================
                        //For Years
                        //==============================
                        intCal.yearsToNotify(years, dateToInsert); 
                        int yearsSpecial = intCal.getYearsRegular();
                        Date dateYearsReg = intCal.getYearsRegDate();

                        dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Seconds
                        //=============================
                        intCal.secondsToNotify(secon, dateToInsert);
                        long secondsSpecial= intCal.getSecondsRegular(); 
                        Date dateSecondsReg = intCal.getSecondsRegDate(); 

                        dbHelper.insertNotifications(6, convertDate(dateSecondsReg), 0, secondsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Hours
                        //=============================
                        intCal.hoursToNotify(hours, dateToInsert); 
                        int hoursSpecial= intCal.getHoursRegular();
                        Date dateHoursReg= intCal.getHoursRegDate(); 

                        dbHelper.insertNotifications(7, convertDate(dateHoursReg), 0, hoursSpecial,FOREIGN_KEY,PRIMARY_ID);



                        //============================================================================================//
                        //Special Intervals
                        //============================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //For Years
                        intCal.specialIntervalYears(years, dateToInsert); 
                        int yearsOnceSpecial =intCal.getYearsSpecial();
                        Date dateYearsSpecial = intCal.getYearsSpDate(); 
                        dbHelper.insertSpecialNotifications(5, convertDate(dateYearsSpecial), yearsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Months
                        intCal.specialIntervalMonths(mon,dateToInsert); 
                        int monthsOnceSpecial= intCal.getMonthsSpecial();
                        Date dateMonthsSpecial = intCal.getMonthsSpDate();
                        dbHelper.insertSpecialNotifications(1, convertDate(dateMonthsSpecial), monthsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Weeks
                        intCal.specialIntervalsWeeks(weeks,dateToInsert); 
                        int weeksOnceSpecial= intCal.getWeeksSpecial(); 
                        Date dateWeeksSpecial = intCal.getWeeksSpDate(); 
                        dbHelper.insertSpecialNotifications(2, convertDate(dateWeeksSpecial), weeksOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Days
                        intCal.specialIntervalsDays(days, dateToInsert); 
                        int daysOnceSpecial= intCal.getDaysSpecial(); 
                        Date dateDaysSpecial = intCal.getDaysSpDate(); 
                        dbHelper.insertSpecialNotifications(3, convertDate(dateDaysSpecial), daysOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Hours
                        intCal.specialIntervalsHours(hours,dateToInsert); 
                        int hoursOnceSpecial= intCal.getHoursSpecial();  
                        Date dateHoursSpecial = intCal.getHoursSpDate(); 
                        dbHelper.insertSpecialNotifications(7, convertDate(dateHoursSpecial), hoursOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Minutes
                        intCal.specialIntervalMinutes(min,dateToInsert); 
                        long minutesOnceSpecial= intCal.getMinutesSpecial(); 
                        Date dateMinutesSpecial= intCal.getMinutesSpDate(); 
                        dbHelper.insertSpecialNotifications(4, convertDate(dateMinutesSpecial), (int)minutesOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Seconds
                        intCal.specialIntervalsSeconds(secon,dateToInsert); 
                        long secondsOnceSpecial= intCal.getSecondsSpecial(); 
                        Date dateSecondsSpecial= intCal.getSecondsSpDate(); 
                        dbHelper.insertSpecialNotifications(6, convertDate(dateSecondsSpecial), secondsOnceSpecial,FOREIGN_KEY,PRIMARY_ID); 
                        i++; 
                    }catch(Exception e){

                    }
                    publishProgress(progress);
                    Asycdialog.setMax(lines);
                    Asycdialog.incrementProgressBy(1);
                }while(c.moveToNext()); 
            }









            // 
            // Dear maintainer:
            // 
            // Once you are done trying to 'optimise' this routine,
            // and have realized what a terrible mistake that was,
            // please increment the following counter as a warning
            // to the next guy:
            // 
            // total_hours_wasted_here = 0;
            //




            //int i=0;
            File toRead = null;
            try{
                if(FLAG ==1){
                    toRead=new File(getApplicationContext().getFilesDir()+"/xxxinders/fileone.txt");
                }else{
                    toRead=new File(getApplicationContext().getFilesDir()+"/xxxinders/output.txt");
                }
                FileInputStream fis=new FileInputStream(toRead);

                Scanner sc=new Scanner(fis);


                String currentLine;
                while(sc.hasNextLine()){


                    currentLine=sc.nextLine();

                    StringTokenizer st=new StringTokenizer(currentLine,"=",false);


                    CONTACT_NAME = toTitleCase(st.nextToken());
                    if(CONTACT_NAME.contains("'")){
                        CONTACT_NAME = CONTACT_NAME.replace("'", "");
                    }

                    // *********
                    String listStr = st.nextToken();

                    String cut = listStr.substring(1, listStr.length() - 1);

                    String[] array = cut.split(",");
                    CONTACT_ID = (array[0].trim());

                    String dateStr = (array[1].trim());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = format.parse(dateStr);
                    java.sql.Date dx = new java.sql.Date(date.getTime());
                    Date key = dx;
                    dateToInsert = String.valueOf(dx); 

                    CONTACT_IMAGE_URI = (array[2].trim());


                    if (isCancelled()) {
                        break;
                    }
                    progress = ("" + Character.toUpperCase(CONTACT_NAME.charAt(0)) + CONTACT_NAME.substring(1) + "\n"+i + " of " + lines + " Contacts"); // Progress displayed here. 



                    years = getDiffYear(key);               // For years elapsed
                    secon = seconds(key);                   // for seconds elapsed
                    min = seconds(key) / 60;                // For minutes elapsed
                    hours = (int) (seconds(key) / 60) / 60; // For hours elapsed
                    mon = months(String.valueOf(key));      // for months elapsed

                    days = daysElapsed(key);                // Days elapsed
                    weeks = daysElapsed(key) / 7;           // For weeks

                    //===============================================================================================================
                    if (dateToInsert.contains("0001-") == true){ //Special Case, we added 0001 to Birthdays Which Have NO Year field. 
                        //===========================================================================================================

                        dbHelper.insert(dateToInsert, CONTACT_NAME, "","", CONTACT_IMAGE_URI, "", "", "", CONTACT_ID, "", ""); // All other fields will be empty, because we don't have a Year. 
                        int PRIMARY_ID = dbHelper.getPrimaryId();
                        String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); 


                        //=====================================================================================================
                        //In this case we are only interested in fetching the year alert for next birthday of this contact -->
                        //=====================================================================================================

                        intCal.yearsToNotify(years, dateToInsert); 
                        int yearsSpecial = intCal.getYearsRegular();
                        Date dateYearsReg = intCal.getYearsRegDate();

                        dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID); 

                    }
                    //=========================================================================
                    //Case when all the Date fields exist and we set up notifications  --->
                    //=========================================================================
                    else if(dateToInsert != "null" && dateToInsert.contains("0001-") != true){

                        dbHelper.insert(dateToInsert, CONTACT_NAME, String.valueOf(days), String.valueOf(hours), CONTACT_IMAGE_URI, String.valueOf(min),String.valueOf(mon), String.valueOf(secon), CONTACT_ID, String.valueOf(weeks), String.valueOf(years));

                        int PRIMARY_ID = dbHelper.getPrimaryId(); // Fetch the PrimaryId (_id) of the above inserted row, its the Foreign key for Notification and SpecialNotifications Table. 
                        String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); // Same as above, but fetches the Name field of the last inserted row. 



                        //=========================================================================
                        //**Database Insertions Notifications Table/ SpecialNotifications Table**
                        //=========================================================================



                        //=======================================================================================//
                        //Regular intervals DB Insertions: 
                        //======================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //======================================================================================//

                        //==============================
                        //For Months 
                        //==============================
                        intCal.monthsNotify(mon, dateToInsert);
                        int monSpecial =  intCal.getMonthRegular(); 
                        Date dateMonReg = intCal.getMonRegDate(); 


                        dbHelper.insertNotifications(1, convertDate(dateMonReg), 0, monSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Weeks 
                        //===============================
                        intCal.weeksToNotify(weeks,dateToInsert); 
                        int weekSpecial = intCal.getWeekRegular();
                        Date dateWeekReg =intCal.getWeekRegDate(); 

                        dbHelper.insertNotifications(2, convertDate(dateWeekReg), 0, weekSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Days
                        //===============================
                        intCal.daysToNotify(days, dateToInsert); 
                        int daysSpecial= intCal.getDaysRegular();  
                        Date dateDaysReg = intCal.getDaysRegDate(); 

                        dbHelper.insertNotifications(3, convertDate(dateDaysReg), 0, daysSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For minutes
                        //===============================
                        intCal.minutesToNotify(min,dateToInsert);
                        long minutesSpecial= intCal.getMinutesRegular();
                        Date dateMinsReg = intCal.getMinutesRegDate(); 

                        dbHelper.insertNotifications(4, convertDate(dateMinsReg), 0,(int) minutesSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //==============================
                        //For Years
                        //==============================
                        intCal.yearsToNotify(years, dateToInsert); 
                        int yearsSpecial = intCal.getYearsRegular();
                        Date dateYearsReg = intCal.getYearsRegDate();

                        dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Seconds
                        //=============================
                        intCal.secondsToNotify(secon, dateToInsert);
                        long secondsSpecial= intCal.getSecondsRegular(); 
                        Date dateSecondsReg = intCal.getSecondsRegDate(); 

                        dbHelper.insertNotifications(6, convertDate(dateSecondsReg), 0, secondsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Hours
                        //=============================
                        intCal.hoursToNotify(hours, dateToInsert); 
                        int hoursSpecial= intCal.getHoursRegular();
                        Date dateHoursReg= intCal.getHoursRegDate(); 

                        dbHelper.insertNotifications(7, convertDate(dateHoursReg), 0, hoursSpecial,FOREIGN_KEY,PRIMARY_ID);



                        //============================================================================================//
                        //Special Intervals
                        //============================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //For Years
                        
                        
                        intCal.specialIntervalYears(years, dateToInsert); 
                        int yearsOnceSpecial =intCal.getYearsSpecial();
                        Date dateYearsSpecial = intCal.getYearsSpDate(); 
                        dbHelper.insertSpecialNotifications(5, convertDate(dateYearsSpecial), yearsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Months
                        intCal.specialIntervalMonths(mon,dateToInsert); 
                        int monthsOnceSpecial= intCal.getMonthsSpecial();
                        Date dateMonthsSpecial = intCal.getMonthsSpDate();
                        dbHelper.insertSpecialNotifications(1, convertDate(dateMonthsSpecial), monthsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Weeks
                        intCal.specialIntervalsWeeks(weeks,dateToInsert); 
                        int weeksOnceSpecial= intCal.getWeeksSpecial(); 
                        Date dateWeeksSpecial = intCal.getWeeksSpDate(); 
                        dbHelper.insertSpecialNotifications(2, convertDate(dateWeeksSpecial), weeksOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Days
                        intCal.specialIntervalsDays(days, dateToInsert); 
                        int daysOnceSpecial= intCal.getDaysSpecial(); 
                        Date dateDaysSpecial = intCal.getDaysSpDate(); 
                        dbHelper.insertSpecialNotifications(3, convertDate(dateDaysSpecial), daysOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Hours
                        intCal.specialIntervalsHours(hours,dateToInsert); 
                        int hoursOnceSpecial= intCal.getHoursSpecial();  
                        Date dateHoursSpecial = intCal.getHoursSpDate(); 
                        dbHelper.insertSpecialNotifications(7, convertDate(dateHoursSpecial), hoursOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Minutes
                        intCal.specialIntervalMinutes(min,dateToInsert); 
                        long minutesOnceSpecial= intCal.getMinutesSpecial(); 
                        Date dateMinutesSpecial= intCal.getMinutesSpDate(); 
                        dbHelper.insertSpecialNotifications(4, convertDate(dateMinutesSpecial), (int)minutesOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Seconds
                        intCal.specialIntervalsSeconds(secon,dateToInsert); 
                        long secondsOnceSpecial= intCal.getSecondsSpecial(); 
                        Date dateSecondsSpecial= intCal.getSecondsSpDate(); 
                        dbHelper.insertSpecialNotifications(6, convertDate(dateSecondsSpecial), secondsOnceSpecial,FOREIGN_KEY,PRIMARY_ID); 
                        writeToSD();
                    }
                    publishProgress(progress);
                    Asycdialog.setMax(lines);
                    Asycdialog.incrementProgressBy(1);
                    i++;
                }
                writeToSD();
            }catch (Exception e){
                System.out.println(e);
            } finally{
                dbHelper.close();
            }
            return "";

        }

        protected void onProgressUpdate(String... values) {

            super.onProgressUpdate(values);
            Asycdialog.setMessage("" + values[0]);
        }


    }

Edit: I found something useful Here

Community
  • 1
  • 1
Skynet
  • 7,820
  • 5
  • 44
  • 80
  • I don't understand why the need for an intermediate file. You can fetch, async do calculations in memory, then write to DB without having to save to a file, which would probably be a huge speed improvement by itself. – William Gaul Feb 07 '14 at 07:42
  • I have to keep a file because it is upto a user to chose only one, two or all the three as initial source. Then at any moment of time he can add on the sources. Also I am doing a data manipulation at a certain point of time each day from the original source (The file). The issue is that should I chose a file or a DB as the initial source? Also doing calculations in memory is not possible, it has to go hand in hand as in for each row in file three rows in three DB tables. – Skynet Feb 07 '14 at 07:45
  • Mind dropping a comment why this question should be closed? – Skynet Feb 07 '14 at 07:47
  • Oh so you pull info from Contacts/FB/G+ into this file, then operate on it based on user input and store results in DB? It would help to have some info about the file format and DB schema, but offhand I'd say yes, your initial source should be a DB as well. – William Gaul Feb 07 '14 at 07:48
  • The file is a simple text file to which I write a HashMap, I collect data in Key Value pairs from Contacts, FB and G+. Then I have three tables in the DB to which I write detailed information based on numerous calculations. – Skynet Feb 07 '14 at 07:50
  • Thank you for keeping the code a secret, but the most probable cause is that you are not using a transaction. – CL. Feb 07 '14 at 09:34
  • The only reason of not posting the code here is that it is almost 900 lines of code, with all the associated functions and rest. But I will make an attempt to edit the question and update it with code, if SO permits. However it would be of great use if you could elaborate on transactions? You mean a DB lock type of thing? – Skynet Feb 07 '14 at 11:53
  • So there it is: The initial data sources are ready, the only thing my Async Task does is to fetch from a file, then add the records to the DB. The code reflects the DB operation minus the functions it uses to calculate values to be added. – Skynet Feb 07 '14 at 11:58

2 Answers2

0

Test your ideas with this and this it allows you to check which part of your code is slow so you fix it.

Adam Radomski
  • 2,515
  • 2
  • 17
  • 28
0

You can store the informations in a local database instead a textfile. It should work much faster than with the textfile and you still can generate the textfile from the local database.

Alexander_Winter
  • 314
  • 1
  • 3
  • 9