android - appwidget onupdate not called as well as button click not working after some time -


i having simple widget has 3 button 3 different system operation.

i made xml in xml folder , code below.

<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"> 

my layout file below

<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" > <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" />   <button android:id="@+id/button2"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_torightof="@+id/button1"   android:text="off"/>   <button android:id="@+id/button3"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_torightof="@+id/button2"  android:text="off"/>    </relativelayout> 

here mainactivity's code extends appwidgetprovider

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<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 button 2    }    else if(abc.equals(intent.getaction()))    {             //logic button 1    }    else if(auto_rotate.equals(intent.getaction()))    {             //logic 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"); } 

here manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.afixi.tetheringwidget" android:versioncode="1" android:versionname="1.0" > <uses-sdk     android:minsdkversion="8"     android:targetsdkversion="18" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <receiver android:name="mainactivity" >         <intent-filter>            <action android:name="android.appwidget.action.appwidget_update" />         </intent-filter>         <meta-data android:name="android.appwidget.provider"            android:resource="@xml/main" />      </receiver> </application> 

it working when first installed after change code , reinstall, not working. please me finding issue, making widget first time think lacking something..thanks in advance!!! n:b:- tried installing in new phone , working, think after time, either not updated or stops receiving pending intent widget!!!


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -