特定のタスクを実行する前に、非同期タスクが終了することを確認するにはどうすればよいですか。非同期タスクがその変数の値を変更した後、変数を使用する必要があります。非同期の実行が完了する前にコードを実行すると、失敗します。何か助けはありますか?非同期タスクは明らかに新しいです。私のコードを見ると、意図したとおりにonPostExecute()を使用していない可能性があるため、アドバイスが役立ちます。私の最初の考えは、非同期タスクに物事を追加し続けることでしたが、連続して実行する必要のあるものがたくさんあるので、これは悪い習慣だと思っています。基本的に、私が思うに、非同期タスクが終了する前にUIスレッドのタスクが実行を開始しないようにするにはどうすればよいですか。
public class MainActivity extends MapActivity {
myJSONmap;
public void onCreate(Bundle savedInstanceState) {
new AsyncStuff().execute();
locatePlace(myJSONmap);
class AsyncStuff extends AsyncTask<Void, Integer, JSONObject> {
@Override
protected JSONObject doInBackground(Void... params) {
jObject = GooglePlacesStuff.getTheJSON(formatedURL);
return null;
}
@Override
protected void onPostExecute(JSONObject result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
myJSONmap = JSONextractor.getJSONHMArrayL(jObject); // getting the parsed data from the JSON object.
//the arraylist contains a hashmap of all the relevant data from the google website.
}
}