Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid home screen widget no gets appWidgetId in Configuration Activity
    primarykey
    data
    text
    <p>I have a widget and I would like to add more than one of them to my screen, so I must control wich widget I'm configuring when I click on it in home screen with appWidgetId.</p> <p>I'm following the documention in android.com, but I'm not getting the appWidgetId when I click on it in home screen.</p> <p>Pieces of my code:</p> <p>//MyWidgetClass</p> <pre><code>@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.i(TAG, CLASS_NAME + " onUpdate"); for (int appWidgetId : appWidgetIds) { updateAppWidget(context, appWidgetManager, appWidgetId); } } public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { Log.d(TAG, CLASS_NAME + " updateAppWidget --- " + appWidgetId); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { Intent settingsIntent = new Intent(context, Widget1x1SettingsActivity.class); settingsIntent .setAction(android.appwidget.AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); //settingsIntent.putExtra("WIDGET_ID", appWidgetId); PendingIntent settingsPendingIntent = PendingIntent.getActivity( context, 0, settingsIntent, 0); RemoteViews remoteViews = null; int layout = R.layout.widget_1x1; remoteViews = new RemoteViews(context.getPackageName(), layout); // Do something ... remoteViews.setOnClickPendingIntent(R.id.widget, settingsPendingIntent); ComponentName thisWidget = new ComponentName(context, MyWidgetClass.class); appWidgetManager.updateAppWidget(thisWidget, remoteViews); } } </code></pre> <p>//Settings class</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, CLASS_NAME + " :: onCreate &gt;&gt;"); super.onCreate(savedInstanceState); mContext = getApplicationContext(); Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); //**//Here appWidgetId is 0 when I click on home screen widget** } .... } </code></pre> <p>And when I click on ok button to finish the configuration activity:</p> <pre><code>AppWidgetManager appWidgetManager = AppWidgetManager .getInstance(getApplicationContext()); MyWidgetClass.updateAppWidget(getApplicationContext(), appWidgetManager, appWidgetId); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); Log.d(TAG, CLASS_NAME + " Putting in RESULT resultValue extras: " + resultValue.getExtras() + " getInt(): " + resultValue.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID)); // it prints correct setResult(RESULT_OK, resultValue); finish(); </code></pre> <p>I don't paste any xml file because I think they are ok.</p> <p>Thanks in advance, SergiBC</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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