Android widget doesn't execute... sometimes

I have a widget that works when it wants to doesn't when... well it doesn't! Specifically, if I reboot my phone and tap on the widget, stuff happens like it should. And perhaps for a while I can continue to tap on the widget and everything works fine. But eventually (like maybe an hour??) it just stops working. From the logcat, none of my code is executed at all, so it's like the tap is never dispatched to my app. My thought process is that since none of my code executes when this happens, the problem must either be in the manifest, or something else that I am unaware of.

Here's the logcat from when it works. The last line from here comes from my code:

 07-20 13:00:54.638: E/MP-Decision(1265): UP Ld:85 Nw:1.990000 Tw:140 rq:1.000000 seq:141.000000
 07-20 13:00:54.818: I/InputReader(533): Touch event's action is 0x0 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=0.4 ]
 07-20 13:00:54.818: I/InputDispatcher(533): Delivering touch to current input target: action: 0x0
 07-20 13:00:54.818: D/lights(533): write_int /sys/class/leds/button-backlight/brightness = 255
 07-20 13:00:54.818: I/PowerManagerService(533): Ulight 0x3->0x7|0x0
 07-20 13:00:54.818: D/PowerManagerService(533): setLightBrightness : mButtonLight : 51
 07-20 13:00:54.908: I/InputReader(533): Touch event's action is 0x1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=]
 07-20 13:00:54.908: I/InputDispatcher(533): Delivering touch to current input target: action: 0x1
 07-20 13:00:54.918: I/AudioPolicyManagerBase(229): getSituationVolume: isBTConnected:0 isHeadConnected:0
 07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getParamFromPolicy  deviceInt = 0, situationInt = 1, situationVolume = 0.500000
 07-20 13:00:54.918: D/AudioService(533): playSoundEffect()
 07-20 13:00:54.918: W/AudioTrack(533): Minimum buffer size corrected from 2048 to 4096
 07-20 13:00:54.918: V/AudioPolicyManagerBase(229): startOutput() output 1, stream 1, session 18
 07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getDeviceForStrategy() from cache strategy 0, device 2
 07-20 13:00:54.918: V/AudioPolicyManagerBase(229): changeRefCount() stream 1, count 1
 07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getDeviceForStrategy() from cache strategy 0, device 2
 07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getNewDevice() selected device 2
 07-20 13:00:54.918: V/AudioPolicyManagerALSA(229): setOutputDevice() output 1 device 2 delayMs 0 force 0
 07-20 13:00:54.918: V/AudioPolicyManagerALSA(229): setOutputDevice output :0x1 mCurDevice:0x2
 07-20 13:00:54.918: V/AudioPolicyManagerALSA(229): setOutputDevice() setting same device 2 or null device for output 1
 07-20 13:00:54.918: D/PHCA_PhcaAppWidgetProvider(2316): onReceive(); action = com.skipmorrow.phca.PhcaAppWidgetProvider.WIDGET_CLICKED

And here's the logcat from when it didn't work.

 07-20 12:53:41.012: I/InputReader(534): Touch event's action is 0x0 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=0.160 ]
 07-20 12:53:41.012: I/InputDispatcher(534): Delivering touch to current input target: action: 0x0
 07-20 12:53:41.012: D/lights(534): write_int /sys/class/leds/button-backlight/brightness = 255
 07-20 12:53:41.012: I/PowerManagerService(534): Ulight 0x3->0x7|0x0
 07-20 12:53:41.012: D/PowerManagerService(534): setLightBrightness : mButtonLight : 51
 07-20 12:53:41.112: I/InputReader(534): Touch event's action is 0x1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=]
 07-20 12:53:41.112: I/InputDispatcher(534): Delivering touch to current input target: action: 0x1
 07-20 12:53:41.112: I/AudioPolicyManagerBase(230): getSituationVolume: isBTConnected:0 isHeadConnected:0
 07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getParamFromPolicy  deviceInt = 0, situationInt = 1, situationVolume = 0.500000
 07-20 12:53:41.112: D/AudioService(534): playSoundEffect()
 07-20 12:53:41.112: W/AudioTrack(534): Minimum buffer size corrected from 2048 to 4096
 07-20 12:53:41.112: V/AudioPolicyManagerBase(230): startOutput() output 1, stream 1, session 153
 07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getDeviceForStrategy() from cache strategy 0, device 2
 07-20 12:53:41.112: V/AudioPolicyManagerBase(230): changeRefCount() stream 1, count 1
 07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getDeviceForStrategy() from cache strategy 0, device 2
 07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getNewDevice() selected device 2
 07-20 12:53:41.112: V/AudioPolicyManagerALSA(230): setOutputDevice() output 1 device 2 delayMs 0 force 0
 07-20 12:53:41.112: V/AudioPolicyManagerALSA(230): setOutputDevice output :0x1 mCurDevice:0x2
 07-20 12:53:41.112: V/AudioPolicyManagerALSA(230): setOutputDevice() setting same device 2 or null device for output 1
 07-20 12:53:41.112: V/AudioPolicyManagerBase(230): releaseOutput() 1

I don't see anything that stands out as being the problem.

Here's the manifest section for the widgetProvider:

 <receiver android:name="com.skipmorrow.phca.PhcaAppWidgetProvider" >
     <intent-filter>
         <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
         <action android:name="com.skipmorrow.phca.PhcaAppWidgetProvider.WIDGET_CLICKED" />
         <action android:name="com.skipmorrow.phca.PhcaAppWidgetProvider.VARIABLE_UPDATED" />
         <action android:name="android.appwidget.action.APPWIDGET_DELETED"/>
         <action android:name="CORRECT_PIN_ENTERED_FOR_WIDGET"/>
     </intent-filter>
     <meta-data android:name="android.appwidget.provider"
                android:resource="@xml/phca_widget_info" />
 </receiver>

Btw, I am using a Samsung Galaxy S3 running ICS. My app has minSdkVersion="8" and targetSdkVersion="8"

No answers over the weekend, but I did some troubleshooting. I still have the problem, but I do have additional information.

The widgets do get updated from the background service that supplies the text for the widgets. But the widgets don't always do what they are supposed to do when they are clicked upon. In other words, even when the clicks aren't getting processed correctly, I can still update the text in the widgets, so the widgets aren't completely broken, if that helps. It also seems that the click responses come and go. That is, after a reboot the clicks seems to work for a while, then maybe stop working for a while, and then start working again. My AppWidgetProvider overrides the onUpdate, onEnabled, onDeleted, onDisabled and onReceive methods, but I only use the onReceive method and manually track each intent. The first line of the onReceive method writes to the log, so I can see that when the clicks aren't working, no code executes in my AppWidgetProvider at all, so I still don't think the problem is in my AppWidgetProvider, and probably in my manifest???

Could it be a permissions problem? Or am I not correctly registering the receivers?


I finally figured it out. It was disabling after rotating the screen. That's why it seemed so random. I never connected the two. This post got me looking in the right direction: Auto Screen Rotation Disabling Widget RemoteView onClick event

链接地址: http://www.djcxy.com/p/50656.html

上一篇: Android小部件,如何在触摸事件中显示数据库中的下一个值?

下一篇: Android小部件不会执行...有时