gpt4 book ai didi

android - 异步任务方法调用在 android 中非常慢

转载 作者:行者123 更新时间:2023-11-30 01:30:05 25 4
gpt4 key购买 nike

我有一个调用后台进程的异步任务方法。当我调用此 summaryCalc 方法时,preexecute 方法会在调用此方法时运行,但 doInBackground 方法需要超过 20 秒才能启动。这需要很长时间。有没有其他方法可以提高调用 doInBackground 方法的速度或任何其他最快的线程执行方法?谢谢。

 @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);
}

最佳答案

您可能正在运行大量异步任务。调用 .execute() 将一一执行它们。尝试调用 .executeOnExecutor()

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

关于android - 异步任务方法调用在 android 中非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35870689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com