How to show widget dialog?

I would like to show a dialog, for example, when I use showDialog (...) in Activity, but I need to do this in widgets, so I can not use showDialog (...). How can i do this?

I tried this with my onReceive method, but it fails:

AlertDialog.Builder builder; builder = new AlertDialog.Builder(context); builder.setMessage("Are you sure?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { db.open(); db.remove_last(); db.close(); dialog.dismiss(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.show(); 

Thanks Valerio

+4
source share
2 answers

Widgets are not designed to support this interaction, and since they run under the UID of your launch, and not from your application, they will not have access to the database. (This is probably the cause of your failure, check the log to find out for sure.)

Run an action in your application that does what you want. If you want it to look like a dialog box, apply Theme.Dialog style:

 <activity android:name=".MyThing" android:label="@string/mythinglabel" android:theme="@android:style/Theme.Dialog" /> 
+4
source

The dialog should appear from the Activity, not from the widget.

0
source

All Articles