public class LoadDataTask extends AsyncTask<String, String, Void> {
ArrayList<Datamodel> list;
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ContactActivity.this);
pDialog.setTitle("loading Contact");
pDialog.setMessage("Please wait...");
pDialog.setCanceledOnTouchOutside(false);
pDialog.show();
}
@Override
protected Void doInBackground(String... params) {
boolean isDbEmpty = loadContactFromDb();
_GetLocation();
if (isDbEmpty) {
publishProgress("Sync Contact");
String numbers = fetchContacts();
list = uploadPhoneNumber(numbers);
System.out.println("count :: " + list.size());
}
return null;
}
@Override
public void onProgressUpdate(String... strings) {
pDialog.setTitle(strings[0]);
}
public boolean loadContactFromDb() {
DataBaseManager dbManager = new DataBaseManager(
ContactActivity.this);
list = dbManager.fetchContactList(_mylat,_mylong);
if (list == null || list.isEmpty()) {
return true;
}
return false;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
DBHelper.dbBackup();
mDataModelArray.clear();
mDataModelArray.addAll(list);
mAdapter.notifyDataSetChanged();
schedueService();
if(pDialog!=null && pDialog.isShowing()){
pDialog.dismiss();
}
}
}
这是我的代码我在pDialog.show()获得异常;在com.lociiapp.ContactActivity $ LoadDataTask.onPreExecute(ContactActivity.java:495) 活动已泄漏窗口com.android.internal.policy.impl.PhoneWindow $ DecorView活动已泄漏窗口如何解决此异常
我曾尝试申请条件,那么还其不工作
尝试把这个代码之前的对话框:)publishProgress()内runOnUiThread(。 – 2014-11-03 06:39:37
代码中的变化请帮助我 – Departure 2014-11-03 06:41:31
您需要创建构造函数并将调用者活动或服务的上下文传递给该构造函数,并将其存储并在创建pDialog时使用它。这样做...它会解决你的问题 – 2014-11-03 06:49:02