views:

28

answers:

1

Hi, i'd like to show a dialog, like when i use showDialog(...) on the Activity, but i need to do that on a widget, so i can't use showDialog(...). How can i do that?

I tried this on my onReceive method but it crash:

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

+2  A: 

Widgets aren't intended to support that kind of interaction, and since they run under the UID of your launcher and not that of your application, they're not going to have access to the database. (That's probably the cause of your crash; look in the log to find out for sure.)

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

<activity
  android:name=".MyThing"
  android:label="@string/mythinglabel"
  android:theme="@android:style/Theme.Dialog"
/>
Blrfl
The database is not the problem, it goes with no problem, it crash also without the db code. I want to create a dialog for confirmation!
Skatephone
Posting the log from the crash would be helpful.
Blrfl