Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT: OK, so you set a <a href="http://developer.android.com/reference/android/app/PendingIntent.html#getBroadcast%28android.content.Context,%20int,%20android.content.Intent,%20int%29" rel="nofollow">getBroadcast</a> PendingIntent on your button with <a href="http://developer.android.com/reference/android/widget/RemoteViews.html#setOnClickPendingIntent%28int,%20android.app.PendingIntent%29" rel="nofollow">setOnClickPendingIntent</a> and perform your update (or call your update method) with the new text from the receiver. Your <a href="http://developer.android.com/reference/android/appwidget/AppWidgetProvider.html" rel="nofollow">AppWidgetProvider</a> class can be your receiver (you can catch your intent in <a href="http://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onReceive%28android.content.Context,%20android.content.Intent%29" rel="nofollow">onReceive</a>), otherwise you create a new class that extends <a href="http://developer.android.com/reference/android/content/BroadcastReceiver.html" rel="nofollow">BroadcastReceiver</a>.</p> <p>EDIT2 (sample code):</p> <p>I didn't run/compile this code so hopefully it will not have errors. This is a simple helper method to get a basic update pending intent with a custom action:</p> <pre><code>public PendingIntent getRefreshPendingIntent(Context context, int appWidgetId){ Intent intent = new Intent("my.package.ACTION_UPDATE_WIDGET"); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } </code></pre> <p>Catch the custom action in onReceive in your overridden AppWidgetProvider class</p> <pre><code>@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); //handle other appwidget actions if (intent.getAction().equals("my.package.ACTION_UPDATE_WIDGET")) { //some code here that will update your widget } //handle other appwidget actions } </code></pre> <p>You will also need to add an IntentFilter for the custom action to your manifest in the appwidget receiver declaration</p> <pre><code>&lt;receiver android:name="my.package.MyWidgetProviderClass" android:label="MyWidget"&gt; &lt;intent-filter&gt; &lt;action android:name="my.package.ACTION_UPDATE_WIDGET"/&gt; &lt;!-- other intent filters --&gt; &lt;/intent-filter&gt; &lt;!-- meta data pointing to widget xml file --&gt; &lt;/receiver&gt; </code></pre> <p>Finally you apply the pending intent to your RemoteViews where ever you are building it so when the button is clicked it will send the my.package.ACTION_UPDATE_WIDGET action, which will be caught by your AppWidgetProvider, where you can (or call a method to) perform your AppWidget update</p> <pre><code>myRemoteViews.setOnClickPendingIntent(R.id.id_of_update_button, getRefreshPendingIntent(context, appWidgetId); </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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