単語のタイトルが謝罪されました。私は(私のonCreate()メソッド内)にしようとしています:ProgressDialog +ポーズコードの実行中に背景が読み込まれる
をいくつか-initialize
-display私はその後、進捗ダイアログ-clear私のバックエンド
からいくつかのデータをロードしながら進行状況ダイアログコードを続ける
典型的な進捗ダイアログソリューションはasynctaskであることを理解していますが、私はこれを試してみました(下記参照)。しかし、これは私が望むようにコード実行をロックしません。 lwpd.execute()の後に来るコードは、既に起こっている読み込みに依存しています。私はこれを過度に複製していますか?私がしたいことをする正しい方法は何ですか?参考のため
、私Asynctask実装:
public class LoadWithProgressDialog extends AsyncTask<Void, Void, Boolean>{
private ProgressDialog pd; //the progress dialog
private String title; //the title of the progress dialog
private String message; //the body of the progress dialog
private Runnable task; //contains the code we want to run in the background
private Context c;
public LoadWithProgressDialog(Context context,String t, String m,Runnable r){
super();
c = context;
task = r;
title = t;
message = m;
}
@Override
protected void onPreExecute(){
pd = ProgressDialog.show(c,title, message, false, false);
}
@Override
protected Boolean doInBackground(Void... params) {
task.run();
return true;
}
@Override
protected void onPostExecute(Boolean result) {
pd.dismiss();
}
}
と
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//initialize variables
LoadWithProgressDialog lwpd = new LoadWithProgressDialog(this,"Loading","Loading Truck Data", new Runnable() {
public void run(){
//code that loads things
}
});
lwpd.execute();
//continue on with my code
}