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