I am working with Android application to show network error.
NetErrorPage.java
package exp.app;
import android.app.Activity;
impor
Change this dialog.cancel();
to dialog.dismiss();
The solution is to call dismiss()
on the Dialog
you created in NetErrorPage.java:114 before exiting the Activity
, e.g. in onPause()
.
Views have a reference to their parent Context
(taken from constructor argument). If you leave an Activity
without destroying Dialog
s and other dynamically created View
s, they still hold this reference to your Activity
(if you created with this as Context
: like new ProgressDialog(this)
), so it cannot be collected by the GC, causing a memory leak.
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 :-).
The dialog needs to be started only after the window states of the Activity are initialized This happens only after onresume.
So call
runOnUIthread(new Runnable(){
showInfoMessageDialog("Please check your network connection","Network Alert");
});
in your OnResume function. Do not create dialogs 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 of showonuithread
In my case finish()
executed immediately after a dialog has shown.
I got this error but it is resolved interesting. As first, i got this error at api level 17. When i call a thread (AsyncTask or others) without progress dialog then i call an other thread method again using progress dialog, i got that crash and the reason is about usage of progress dialog.
In my case, there are two results that;
show();
method of progress dialog before first thread starts then i took dismiss();
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();
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();
}