Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid widget button works only after 2nd install of app
    text
    copied!<p>I am using this code make the user able to open the application only by clicking on the widget. The problem is that, when I install the app, nothing happens when I click on the widget. But when I install it again, it is working fine. Any ideas?</p> <pre><code>public class HelloWidget extends AppWidgetProvider { public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget"; public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget"; private static final int REQUEST_CODE_ONE = 10; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Intent intent = new Intent(context, UpdateService.class); context.startService(intent); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); Intent configIntent = new Intent(context, MainActivity.class); configIntent.setAction(ACTION_WIDGET_CONFIGURE); PendingIntent configPendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_ONE, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.ImageView01, configPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); } @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[] { appWidgetId }); } } else { if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) { String msg = "null"; try { msg = intent.getStringExtra("msg"); } catch (NullPointerException e) { Log.e("Error", "msg = null"); } Toast.makeText(context, "Out: " + msg, Toast.LENGTH_SHORT).show(); } super.onReceive(context, intent); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload