[ACCEPTED]-android activity has leaked window com.android.internal.policy.impl.phonewindow$decorview Issue-android-alertdialog
Thank you Guys to give me many suggestions. Finally I got a solution. That is i have 12 started the NetErrorPage intent two times. One 11 time, i have checked the net connection 10 availability and started the intent in page 9 started event. second time, if the page 8 has error, then i have started the intent 7 in OnReceivedError event. So the first time 6 dialog is not closed, before that the second 5 dialog is called. So that i got a error.
Reason for the Error: I 4 have called the showInfoMessageDialog method two 3 times before closing the first one.
Now I 2 have removed the second call and Cleared 1 error :-).
Change this dialog.cancel();
to dialog.dismiss();
The solution is to call 8 dismiss()
on the Dialog
you created in NetErrorPage.java:114 before exiting 7 the Activity
, e.g. in onPause()
.
Views have a reference to 6 their parent Context
(taken from constructor argument). If 5 you leave an Activity
without destroying Dialog
s and other 4 dynamically created View
s, they still hold this 3 reference to your Activity
(if you created with 2 this as Context
: like new ProgressDialog(this)
), so it cannot be collected 1 by the GC, causing a memory leak.
In my case finish()
executed immediately after a 1 dialog has shown.
Please try this Way And Let me know :
Context mContext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.neterrorlayout);
mContext=NetErrorPage.this;
Button reload=(Button)findViewById(R.id.btnReload);
reload.setOnClickListener(this);
showInfoMessageDialog("Please check your network connection","Network Alert");
}
public void showInfoMessageDialog(String message,String title)
{
new AlertDialog.Builder(mContext)
.setTitle("Network Alert");
.setMessage(message);
.setButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which)
{
dialog.cancel();
}
})
.show();
}
0
The dialog needs to be started only after 5 the window states of the Activity are initialized This 4 happens only after onresume.
So call
runOnUIthread(new Runnable(){
showInfoMessageDialog("Please check your network connection","Network Alert");
});
in your 3 OnResume function. Do not create dialogs 2 in OnCreate
Edit:
use this
Handler h = new Handler();
h.postDelayed(new Runnable(){
showInfoMessageDialog("Please check your network connection","Network Alert");
},500);
in your Onresume instead 1 of showonuithread
@Override
protected void onPostExecute(final Boolean success) {
mProgressDialog.dismiss();
mProgressDialog = null;
setting the value null works for me
0
I got this error but it is resolved interesting. As 7 first, i got this error at api level 17. When 6 i call a thread (AsyncTask or others) without 5 progress dialog then i call an other thread 4 method again using progress dialog, i got 3 that crash and the reason is about usage 2 of progress dialog.
In my case, there are 1 two results that;
- I took
show();
method of progress dialog before first thread starts then i tookdismiss();
method of progress dialog before last thread ends.
So :
ProgresDialog progressDialog = new ...
//configure progressDialog
progressDialog.show();
start firstThread {
...
}
...
start lastThread {
...
}
//be sure to finish threads
progressDialog.dismiss();
- This is so strange but that error has an ability about destroy itself at least for me :)
The way I got around this issue is by not 3 calling intent within a dialog. **** use 2 syntax applicable to activity or fragment 1 accordingly
@Override
public void onClick(DialogInterface dialog, int which) {
checkvariable= true;
getActivity().finish();
}
@Override
public void onStop() {
super.onStop();
if (checkvariable) {
startActivity(intent);
}
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.