I get the following Android exception when I try to open a dialog. Can someone please help me understand what is going on and how can I fix this problem?
and
In my case I was trying to create my dialog like this:
new Dialog(getApplicationContext());
So I had to change for:
new Dialog(this);
And it works fine for me ;)
I got this exception, when I tried to open Progress Dialog under Cordova Plugin by using below two cases,
new ProgressDialog(this.cordova.getActivity().getParent());
new ProgressDialog(this.cordova.getActivity().getApplicationContext());
Later changed like this,
new ProgressDialog(this.cordova.getActivity());
Its working fine for me.
Hello there if you are using adapter there might be a chance.
All you need to know when you used any dialog in adapter,getContext(),context or activity won't work sometime.
Here is the trick I used
v.getRootView().getContext()
where v is the view object you are referencing.
Eg.
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DatePickerDialog(v.getRootView().getContext(), date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
If you are getting this problem because of alert dialog.
Refer [here][1] But it is same concept.
[1]: https://stackoverflow.com/questions/6367771/displaying-alertdialog-inside-a-custom-listadapter-class
Try getParent()
at the argument place of context
like new AlertDialog.Builder(getParent());
Hope it will work, it worked for me.
I tried with this in the context field:
this.getActivity().getParent()
and it works fine for me. This was from a class which extends from "Fragment":
public class filtro extends Fragment{...
I solved this error by add below user-permission in AndroidManifest.xml
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Also, Initialize Alert dialog with Activity Name:
AlertDialog.Builder builder = new AlertDialog.Builder(YourActivity.this);
For More Details, visit==> How to create Alert Dialog in Android