私はAsyncTaskと仲良くしようとしています..私の問題は、プロシージャの出力に基づいてテキストビューのテーブルを動的に作成していたことでした..しかし、asynctaskを使用することで、より効率的な方法でそれを行うことができると考えました..だから、私がしたことは次のとおりです:
private class DisplayReport extends AsyncTask<Void, Void, Boolean>{
protected void onPreExecute(){
//Message -- "Please wait while the Report Loads..."
}
@Override
protected Boolean doInBackground(Void... params) {
//Here i fetch the data from the procedure via a web service
//parse the result of web service and set a bool variable true or false based on whether the dataset fetched is empty or not.
}
protected void onPostExecute(Boolean value){
if(value == true){
"Please try again later!!"
}
else{
runOnUiThread(GenTable);
}
}
private Runnable GenTable = new Runnable(){
public void run(){
try {
displayReport(result); // in this method i build the table.
} catch (Exception e) {
ad.setTitle("Error..");
ad.setMessage(e.toString());
}
}
};
}
上記の非同期クラスは、アクティビティを拡張するメイン クラスの内部クラスです。そして、これが私がasynctaskを実行している方法です..
DisplayReport dr = new DisplayReport();
dr.execute();
今、デバッグする"source not found" error on dr.execute()..
と、ネットでたくさん検索しようとしましたが、具体的なものは何も見つかりません。また、私のアプローチが間違っている場合はお知らせください。
ありがとう!