【发布时间】:2018-01-06 04:50:30
【问题描述】:
我有这个功能,它可以检查用户所做的选择。 所以例如 有4个选择:
- InfoOfUp
- InfoOfArt
- 教区信息
- InfoOfAteneo。
所以当用户选择 InfoOfUp 和 InfoOfArt 然后在下一个活动中,我将单击一个包含函数的按钮: selected() 它将检查用户选择的项目。如果用户选择项目 InfoOfUp 它将运行一个特定的功能,如果用户选择项目 InfoOfArt 它也将运行一个特定的功能
问题是每个项目都有自己的功能,每个项目都有进度对话框,标记该功能是否已经完成。 所以用户选择了2个项目,因为同时调用了2个函数,所以出错了;
我希望函数被调用 1by1 函数等待另一个函数完成。
为避免混淆,我将方法称为函数。
public void selected() {
if (InfoOfUp.select == 1) {
if (ayala == 0) {
ayala();
ayala = 1;
} else if (ayala == 1) {
}
}
if (InfoOfArt.select == 1) {
if (art == 0) {
ArtInIsland();
art = 1;
} else if (art == 1) {
}
}
if (InfoOfParish.select == 1) {
if (parish == 0) {
parish();
parish = 1;
} else if (parish == 1) {
}
}
if (InfoOfAteneo.select == 1) {
if (ateneo == 0) {
ateneogallery();
ateneo = 1;
} else if (ateneo == 1) {
}
}
另外,如果函数调用,它会运行一个异步任务来获取数据。 这是我的异步任务:
public class connectAsyncTask3 extends AsyncTask<Void, Void, String> {
private ProgressDialog progressDialog;
private traffic traffic;
private boolean displayDestinationDetails;
String url;
boolean launchDestination;
connectAsyncTask3(String urlPass, traffic traffic, boolean displayDestinationDetails) {
this.url = urlPass;
this.traffic = traffic;
this.displayDestinationDetails = displayDestinationDetails;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
try {
super.onPreExecute();
progressDialog = new ProgressDialog(traffic.this);
progressDialog.setMessage("Fetching route, Please wait...");
progressDialog.setIndeterminate(true);
progressDialog.show();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected String doInBackground(Void... params) {
JSONParser jParser = new JSONParser();
String json = jParser.getJSONFromUrl(url);
return json;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progressDialog.hide();
if (result != null) {
Log.d("momo2", " : " + result);
traffic.drawPath(result);
speakOut();
}
if (displayDestinationDetails) {
Intent i = new Intent(traffic.this, poppers.class);
i.putExtra("currentMarker", traffic.markers.size());
traffic.startActivity(i);
}
}
}
【问题讨论】:
-
制作方法
synchronized不够用? -
@j.e.gr 我不熟悉同步。
标签: android function methods call