Android Activity Has Leaked Window Com.Android.Internal.Policy.Impl.
Phonewindow$Decorview Issue

android activity has leaked window com.android.internal.policy.impl.phonewindow$
decorview Issue

Thank you Guys to give me many suggestions. Finally I got a solution. That is i have started the NetErrorPage intent two times. One time, i have checked the net connection availability and started the intent in page started event. second time, if the page has error, then i have started the intent in OnReceivedError event. So the first time dialog is not closed, before that the second dialog is called. So that i got a error.

Reason for the Error: I have called the showInfoMessageDialog method
two times before closing the first one.

Now I have removed the second call and Cleared error :-).

Activity has leaked window com.android.internal.policy.impl.PhoneWindow$
DecorView@44f72ff0 that was originally added here

You are leaking the dialog. You need to call pDialog.dismiss(); in the onPostExecute() method of the async task. You should also put...

if(pDialog != null)
pDialog.dismiss();

in your onPause() method of the activity on the main thread. This will make sure the window is not leaked, even if your application loses the foreground while doing some background execution. You should have something like this...

public class Login extends Activity implements View.OnClickListener{

ProgressDialog pd;

public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.login);
pd = null;
}

@Override
public void onPause(){

super.onPause();
if(pd != null)
pd.dismiss();
}

public void onClick(View v){
new SendTask().execute("");
}

/*
No networking allowed on the main thread.
*/
private class SendTask extends AsyncTask<String,String,String>{

int result;

@Override
protected void onPreExecute(){
pd = ProgressDialog.show(Login.this,"","Retrieving Inbox...", true,false);
}

@Override
protected String doInBackground(String...strings){

//do networking here
result = account.prepare();
return null;
}

@Override
protected void onPostExecute(String unused){

//check result
pd.dismiss();
Intent intent = new Intent(Login.this,NextActivity.class);
finish();
startActivity(intent);
}
}
}

Activity has leaked window com.android.internal.policy.impl.PhoneWindows
$DecorView{42d9a800

It usually happens when you are trying try to dismiss any dialog which is no longer created or exist.

Possible reasons are

  • Your activity is no longer exists but your task is still running and trying to dismiss the dialog.

  • Your app is crashing somewhere in doInBackgrond.

Check values of yopur JsonObject "c" and better to add null checks for JsonObject or wherever there is a chance for NullPointerException occurrence in your code (doInbackground here).

onPostExcute runs in Main/UI thread not in background thread.

EDIT :

Replace your doInBackground code with this and make sure you are not switching the Activity in between the task is running :

protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_venues, "GET", params);

if(json!=null){
// Check your log cat for JSON reponse
Log.d("All Venues: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// venues found
// Getting Array of Venues
venues = json.getJSONArray(TAG_VENUES);
// looping through All Venues
if(venues !=null){
for (int i = 0; i < venues.length(); i++) {
JSONObject c = venues.getJSONObject(i);
// Storing each json item in variable
if(c!=null){
String id = c.getString(TAG_VENUE_ID);
String name = c.getString(TAG_VENUE_NAME);
}
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_VENUE_ID, id);
map.put(TAG_VENUE_NAME, name);
// adding HashList to ArrayList
venuesList.add(map);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}

Activity has leaked window com.android.internal.policy.impl.PhoneWindow$
DecorView@46029dd0

Leak comes because you are keeping reference of activity after it destroyed also so use

if(progressDialog !=null)
{
progressDialog = null;
}
progressDialog = new ProgressDialog(this.getApplicationContext());
progressDialog.setMessage("Uploading data, please wait...");

OR

use this it will help

@Override
public void onClick(View v) {

switch (v.getId()) {
case R.id.btnSubmitNow:
// Submit now

// Sample upload image
UploadImage.uploadImage("testimage");

new AsyncTask<Void, Void, Void>() {

// called before execution // main/UI thread
protected void onPreExecute() {

progressDialog = new ProgressDialog(SignOut_Activity.this);
progressDialog.setMessage("Uploading data, please wait...");

progressDialog.show();
};

@Override
protected Void doInBackground(Void... params) {
// Submit the store data
StoreData.postData(StoreList_Activity.storesList
.get(StoresListAdapter.Position));
return null;
}

// on store data uploaded // main/UI thread
protected void onPostExecute(Void result) {
progressDialog.dismiss();
setSignOut();
StoreList_Activity.storesList
.get(StoresListAdapter.Position).isSubmitted = true;
SignOut_Activity.this.finish();
};

}.execute();

Activity has leaked window com.android.internal.policy.impl.PhoneWindow$
DecorView@46368a28 that was originally added here

Your Handler needs to be created in your UI thread for it to be able to update the UI.
I would then use the sendMessage method of the handler, rather than posting a runnable:

private static final int HANDLER_MESSAGE_ERROR = 0;
private static final int HANDLER_MESSAGE_COMPLETED = 1;
...
private void connectAndGetRoute(){
new Thread(){
@Override
public void run() {
try {
if(!connectTo9292ov()) return;

} catch(UnknownHostException e){
sendMessage(HANDLER_MESSAGE_ERROR);
} catch (ClientProtocolException e) {
sendMessage(HANDLER_MESSAGE_ERROR);
} catch (IOException e) {
sendMessage(HANDLER_MESSAGE_ERROR);
} finally {
sendMessage(HANDLER_MESSAGE_COMPLETED);
}
}
private void sendMessage(int what){
Message msg = Message.obtain();
msg.what = what;
mHandler.sendMessage(msg);
}
}.start();

}
...
private Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch(msg.what){
case HANDLER_MESSAGE_ERROR:
Toast.makeText(mContext, "failed to connect to server", Toast.LENGTH_LONG).show();
break;
case HANDLER_MESSAGE_COMPLETED:
mProgressDialog.dismiss();
showOnScreen();
break;
default:
Log.w("MyTag","Warning: message type \""+msg.what+"\" not supported");
}
}
}


Related Topics



Leave a reply



Submit