chellapandi k
chellapandi k

Reputation: 299

Asynchronous Task Method Calling is Very Slow in android

I've an Asynchronous task method, that calls background process. when i call this summaryCalc method, preexecute method runs when this method calls but doInBackground method takes more than 20 seconds to start. it takes a long time. is there any other way to improve the speed of calling doInBackground method or any other fastest way to execute thread? Thank you.

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_summary_date_select);
    btnSearch = (Button) findViewById(R.id.btnSearch);

    btnSearch.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                summaryCalc();                
        }
    });
}
 /**
 * method to create asynchronous task to realign summary data
 */
public void summaryCalc() {
    new AsyncTask<Void, Void, String>() {
        ProgressDialog dialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog = new ProgressDialog(SummaryDateSelectActivity.this);
            dialog.setTitle(getResources().getString(R.string.app_name));
            dialog.setMessage(getResources().getString(R.string.please_wait));
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        }

        @Override
        protected String doInBackground(Void... params) {
            ExtraSettingsDS settingsDS = new ExtraSettingsDS(getApplicationContext());
            ExtraSettingsDO settingsDO = settingsDS.getExtraSettingsValues();
            WeeklySummaryRecovery summaryRecovery = new WeeklySummaryRecovery(getApplicationContext());
             /*Insert missing account order data*/
            summaryRecovery.insertMissingAccOrderData();

            if (settingsDO.getAccManage() == 0) {
                summaryRecovery.summaryInsertForSeparateAccManage();
            } else {
                summaryRecovery.summaryInsertForJoinAccManage();
            }
            settingsDS.updateWeeklyFinishedDate();
            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            dialog.dismiss();
            intent = new Intent(getApplicationContext(), SummaryDetailsShowActivity.class);
            intent.putExtra(KandhaConstants.IE_NEXT_ACTIVITY, accCheck);
            intent.putExtra(KandhaConstants.IE_DAY_OF_LINE, currentDay);
            intent.putExtra(KandhaConstants.IE_START_DATE, date);
            startActivity(intent);
            finish();
        }

    }.execute(null, null, null);
}

Upvotes: 1

Views: 743

Answers (1)

vkislicins
vkislicins

Reputation: 3391

It is possible you have a lot of async tasks running. Calling .execute() will execute them one by one. Try calling .executeOnExecutor() instead.

http://developer.android.com/reference/android/os/AsyncTask.html

Upvotes: 1

Related Questions