android - Why the base class onReceive() function doesn't call the onUpdate()? -



android - Why the base class onReceive() function doesn't call the onUpdate()? -

i have simple home screen widget application shows toast on button click. on fortunately display toast on power-up (or after update apk in emulator). button click has pending intent send action_appwidget_update onreceive() function of base of operations class doesn't handle it.

here's code:

public class wordwidget extends appwidgetprovider { @override public void onreceive(context ctxt, intent intent) { log.d("wordwidget.onreceive", "onreceive"); log.d("wordwidget.onreceive", intent.getaction()); if (intent.getaction()==null) { ctxt.startservice(new intent(ctxt, updateservice.class)); } else { super.onreceive(ctxt, intent); } } @override public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids) { // prevent anr timeouts, perform update in service log.d("wordwidget.onupdate", "onupdate"); context.startservice(new intent(context, updateservice.class)); } public static class updateservice extends service { @override public void onstart(intent intent, int startid) { log.d("updateservice.onstart", "onstart"); // build widget update today remoteviews updateviews = buildupdate(this); // force update widget home screen componentname thiswidget = new componentname(this, wordwidget.class); appwidgetmanager manager = appwidgetmanager.getinstance(this); manager.updateappwidget(thiswidget, updateviews); } public remoteviews buildupdate(context context) { log.d("updateservice.buildupdate", "buildupdate"); remoteviews updateviews = new remoteviews(context.getpackagename(), r.layout.widget_word); intent defineintent = new intent(context, wordwidget.class); defineintent.setaction(appwidgetmanager.action_appwidget_update); pendingintent pendingintent = pendingintent.getbroadcast(context, 0, defineintent, 0); updateviews.setonclickpendingintent(r.id.widget, pendingintent); showtoast(context); homecoming updateviews; } private void showtoast(context context){ log.d("updateservice.showtoast", "showtoast"); toast.maketext(context, "it working...", toast.length_long).show(); } @override public ibinder onbind(intent intent) { // don't need bind service homecoming null; } } }

on power-up (or after beingness re-installed) widget shows toast, here's logcat:

01-17 13:03:10.855: i/activitymanager(72): start proc com.example.android.simplewiktionary broadcast com.example.android.simplewiktionary/.wordwidget: pid=564 uid=10036 gids={3003} 01-17 13:03:11.045: d/wordwidget.onreceive(564): onreceive 01-17 13:03:11.045: d/wordwidget.onreceive(564): android.appwidget.action.appwidget_update 01-17 13:03:11.054: d/wordwidget.onupdate(564): onupdate 01-17 13:03:11.075: d/updateservice.onstart(564): onstart 01-17 13:03:11.075: d/updateservice.buildupdate(564): buildupdate 01-17 13:03:11.094: d/updateservice.showtoast(564): showtoast 01-17 13:03:12.655: d/dalvikvm(72): gc_explicit freed 971k, 47% free 13550k/25159k, paused 7ms+52ms

now 1 time started, if click on button, here's logcat:

01-17 13:04:16.095: d/dalvikvm(126): gc_explicit freed 72k, 14% free 14016k/16135k, paused 3ms+3ms 01-17 13:04:16.277: d/wordwidget.onreceive(564): onreceive 01-17 13:04:16.277: d/wordwidget.onreceive(564): android.appwidget.action.appwidget_update 01-17 13:04:21.365: d/dalvikvm(564): gc_explicit freed 71k, 5% free 6307k/6595k, paused 3ms+2ms

as can see onupdate() not called onreceive() base of operations class function...

could help me this?

thanks.

i found reason why own onupdate() wasn't executed super.onreceive() on button click.

creating intent action set action_appwidget_update not plenty trigger phone call of override onupdate() function super.onreceive() call. according code of onreceive() function of appwidgetprovider class, intent must have info in extras field. why onupdate() phone call first time (when real action_appwidget_update intent system) , not when click on button...

here's code appwidgetprovider.java file:

// begin_include(onreceive) public void [more ...] onreceive(context context, intent intent) { // protect against rogue update broadcasts (not security issue, // filter bad broacasts out subclasses less crash). string action = intent.getaction(); if (appwidgetmanager.action_appwidget_update.equals(action)) { bundle extras = intent.getextras(); if (extras != null) { int[] appwidgetids = extras.getintarray(appwidgetmanager.extra_appwidget_ids); if (appwidgetids != null && appwidgetids.length > 0) { this.onupdate(context, appwidgetmanager.getinstance(context), appwidgetids); } } } else if (appwidgetmanager.action_appwidget_deleted.equals(action)) { bundle extras = intent.getextras(); if (extras != null && extras.containskey(appwidgetmanager.extra_appwidget_id)) { final int appwidgetid = extras.getint(appwidgetmanager.extra_appwidget_id); this.ondeleted(context, new int[] { appwidgetid }); } } else if (appwidgetmanager.action_appwidget_enabled.equals(action)) { this.onenabled(context); } else if (appwidgetmanager.action_appwidget_disabled.equals(action)) { this.ondisabled(context); } }

thanks.

android logcat

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -