Android小部件有时不执行...

时间:2012-07-20 17:15:54

标签: android widget

我有一个小部件可以在它想要的时候工作......好吧它没有!具体来说,如果我重新启动手机并点击小部件,就会发生类似的情况。也许有一段时间我可以继续点击小部件,一切正常。但最终(也许一小时?)它就停止了工作。从logcat开始,我的代码都没有被执行,所以就像点击从未发送到我的应用程序一样。我的思维过程是因为当这种情况发生时我的代码都没有执行,所以问题必须在清单中,或者是我不知道的其他内容。

这是logcat的工作原理。这里的最后一行来自我的代码:

 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

这是logcat从不起作用的时候。

 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

我没有看到任何突出的问题。

这是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>
是的,我正在使用运行ICS的三星Galaxy S3。我的应用有minSdkVersion =“8”和targetSdkVersion =“8”

周末没有答案,但我做了一些故障排除。我仍有问题,但我确实有其他信息。

小部件确实从提供小部件文本的后台服务更新。但是,当小部件被点击时,小部件并不总是按照它们应该做的那样做。换句话说,即使没有正确处理点击,我仍然可以更新小部件中的文本,因此小部件不会完全被破坏,如果这有帮助的话。似乎点击响应来来去去。也就是说,重启后点击似乎工作了一段时间,然后可能会停止工作一段时间,然后再开始工作。我的AppWidgetProvider会覆盖onUpdate,onEnabled,onDeleted,onDisabled和onReceive方法,但我只使用onReceive方法并手动跟踪每个intent。 onReceive方法的第一行写入日志,所以我可以看到,当点击不起作用时,我的AppWidgetProvider中根本没有代码执行,所以我仍然认为问题不在我的AppWidgetProvider中,可能在我的清单???

这可能是权限问题吗?或者我没有正确注册接收器?

1 个答案:

答案 0 :(得分:1)

我终于明白了。旋转屏幕后禁用。这就是它似乎随机的原因。我从来没有将两者联系起来这篇文章让我看向正确的方向: Auto Screen Rotation Disabling Widget RemoteView onClick event