Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a dialog box from a widget?

I couldnt find anywhere a case that a widget launches a dialog box when it is clicked. Do you have any ideas?

I have this code

public void onUpdate(Context c, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
    final int N = appWidgetIds.length;
    AppWidgetManager mgr = AppWidgetManager.getInstance(c);
     for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];
    RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget_layout);
    Intent fireDialog = new Intent(c,Execute.class);

    Toast test=Toast.makeText(c.getApplicationContext(),"onUpdate",Toast.LENGTH_LONG);
    test.show();
    PendingIntent pendingIntent = PendingIntent.getActivity(c, appWidgetId, fireDialog, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.Button, pendingIntent);
    Log.w(LOG_TAG,"Called");
    mgr.updateAppWidget(appWidgetId, views);
     }
}
like image 939
JustCurious Avatar asked Dec 16 '22 07:12

JustCurious


1 Answers

I am assuming here that by "widget" you mean "app widget", the interactive elements an application can add to the user's home screen.

An app widget cannot display a Dialog, as that can only be done by an Activity. Your app widget can start up an Activity, though, via startActivity(). And, you can theme your activity to look like a dialog, by adding android:theme="@android:style/Theme.Dialog" to your element.

like image 189
CommonsWare Avatar answered Jan 12 '23 01:01

CommonsWare