是否有任何使用AsyncTask而不傳入任何參數?我目前正在傳遞一個空字符串,但我沒有做任何事的:使用異步任務
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "" });
class DownloadWebPageTask extends AsyncTask<String, Void, String> {
private final ProgressDialog dialog = new ProgressDialog(MainScreen.this);
@Override
protected void onPreExecute() {
dialog.setMessage("Gathering data for\n"+selectedSportName+".\nPlease wait...");
dialog.show();
}
@Override
protected String doInBackground(String... urls) {
//go do something
return "";
}
@Override
protected void onPostExecute(String result) {
dialog.dismiss();
startTabbedViewActivity();
}
}
private void startTabbedViewActivity(){
Intent intent = new Intent(MainScreen.this, TabbedView.class);
intent.putExtra(SPORT_NAME_EXTRA, selectedSportName);
intent.putExtra(HEADLINES_FOR_SPORT_EXTRA, existingSportHeadlines.get(selectedSportName));
intent.putExtra(SCORES_FOR_SPORT_EXTRA, existingSportScores.get(selectedSportName));
intent.putExtra(SCHEDULE_FOR_SPORT_EXTRA, existingSportSchedule.get(selectedSportName));
startActivity(intent);
}
出於某種原因,當我運行如圖所示的代碼,並沒有在doInBackground發生(),對話框自敗,並啓動TabbedView活動。
但是,當我使用doInBackground()運行一些代碼時,對話框消失了,但TabbedView活動不會啓動。所以我想知道我是否可以做任何不同的事情?
對於你的問題看我的答案的第一部分。對於第二部分,您可以在「doInBackground()」中運行代碼時是否放置斷點並查看是否調用了'onPostExecute()'? –
當然,我會給那個鏡頭 –
那麼onPostExecute()的方法簽名是什麼?它說它必須重寫超類型,刪除@override註釋 –