title: appwidget onupdate not called as well as button click not working after some time
body: <p>I am having a simple widget which has three button for three different system operation.</p>
  
  <p>I made a XML in xml folder and the code is below.</p>
  
  <pre><code>&lt;appwidget-provider 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:minWidth="292dp" 
  android:updatePeriodMillis="86400000" 
  android:minHeight="32dp"     
  android:initialLayout="@layout/activity_main"&gt;
  </code></pre>
  
  <p>
  <strong>my layout file is below</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="80dp"
  android:gravity="top"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity"
  android:background="#D8F781"
  &gt;
  &lt;Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Off" /&gt;
    &lt;Button android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/button1"
    android:text="off"/&gt;
  
   &lt;Button android:id="@+id/button3"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_toRightOf="@+id/button2"
   android:text="off"/&gt;   
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>Here is the MainActivity's code which extends AppWidgetProvider</strong></p>
  
  <pre><code>public class MainActivity extends AppWidgetProvider{
  Context ctx;
  private static final String XYZ    = "xyz";
  private static final String ABC    = "abc";
  private static final String CFV    = "cfv";
  
  
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
  int[] appWidgetIds) {
    ctx = context;
    for(int i=0; i&lt;appWidgetIds.length; i++){
    int currentWidgetId = appWidgetIds[i];
    RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.activity_main);     
  
    views.setOnClickPendingIntent(R.id.button2, getPendingSelfIntent(context, XYZ));
    views.setOnClickPendingIntent(R.id.button1, getPendingSelfIntent(context, ABC));
    views.setOnClickPendingIntent(R.id.button3, getPendingSelfIntent(context, CFV));
    appWidgetManager.updateAppWidget(currentWidgetId,views);      
    Toast.makeText(context, "widget used", Toast.LENGTH_SHORT).show();    
    }
   }
  
  protected PendingIntent getPendingSelfIntent(Context context, String action) {
     Log.v("ONMESSAGE", action);
     Intent intent = new Intent(context, getClass());
     intent.setAction(action);
     return PendingIntent.getBroadcast(context, 0, intent, 0);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
     // TODO Auto-generated method stub
     super.onReceive(context, intent);
     ctx = context;
     final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
     RemoteViews remoteViews;
     AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);       
     ComponentName watchWidget;
     remoteViews = new RemoteViews(context.getPackageName(), R.layout.activity_main);
     if (XYZ.equals(intent.getAction())) {  
         //Logic for button 2
     }
     else if(ABC.equals(intent.getAction()))
     {      
        //Logic for button 1
     }
     else if(AUTO_ROTATE.equals(intent.getAction()))
     {      
        //Logic for button 3
     }
  
  
     watchWidget = new ComponentName( context, MainActivity.class );
     (AppWidgetManager.getInstance(context)).updateAppWidget( watchWidget, remoteViews );
   }
   @Override
  public void onEnabled(Context context) {
      // TODO Auto-generated method stub
      super.onEnabled(context);
      Log.v("ONMESSAGE", "Working");
  }
  </code></pre>
  
  <p><strong>Here is the manifest</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.afixi.tetheringwidget"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="18" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;receiver android:name="MainActivity" &gt;
          &lt;intent-filter&gt;
             &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
          &lt;/intent-filter&gt;
          &lt;meta-data android:name="android.appwidget.provider"
             android:resource="@xml/main" /&gt;
       &lt;/receiver&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>It was all working when first installed however after I change the code and then reinstall, now its not working. I am making widget for the first time.</p>
  
  <p>N:B:-  just tried installing it in a new phone and now it is working, I think after some time, it either does not get updated or stops receiving pending intent from widget!</p>