lgfischer / WidgetHostExample

Source code for my blog post at http://leonardofischer.com/hosting-android-widgets-my-appwidgethost-tutorial/
37 stars 12 forks source link

Analog Clock AppWidget fails to launch Alarm Clock Activity #1

Open jimcrayne opened 9 years ago

jimcrayne commented 9 years ago

I already left a comment on your blog, but it ocurred to me that it might be better to have it in the issue tracker here.

Running on a simple android virtual device (android 2.2, stock image from the SDK). I notice that when i add the Analog Clock AppWidget, It displays and updates fine, but when I click it, I get an IntentSender Exception, which I only notice because I am looking at the LogCat, otherwise the interaction is ignored.

From the home screen the Analog Clock AppWidget launches the Alarm Clock Activity when you click it. Why does it behave differently in our AppWidgetHost? How can we make it work the same way?

jimcrayne commented 9 years ago

Apparently this issue is not consistent, for the program worked on my latest run.

I do not know what changed the state, but I did do two things which modified the environment possibly, 1) I added the Analog Clock AppWidget to the homescreen as well, and 2) I didn't launch the app after a fresh install using the run button in eclipse, but rather I launched it by selecting it's icon in the apps drawer (or whatever that is called).

The first several times i tried to click the clock widget after a fresh install (running from eclipse), I got this in the LogCat:

10-03 01:19:57.985: E/RemoteViews(739): Cannot send pending intent: 
10-03 01:19:57.985: E/RemoteViews(739): android.content.IntentSender$SendIntentException
10-03 01:19:57.985: E/RemoteViews(739):     at android.app.ContextImpl.startIntentSender(ContextImpl.java:640)
10-03 01:19:57.985: E/RemoteViews(739):     at android.widget.RemoteViews$SetOnClickPendingIntent$1.onClick(RemoteViews.java:157)
10-03 01:19:57.985: E/RemoteViews(739):     at android.view.View.performClick(View.java:2408)
10-03 01:19:57.985: E/RemoteViews(739):     at android.view.View$PerformClick.run(View.java:8816)
10-03 01:19:57.985: E/RemoteViews(739):     at android.os.Handler.handleCallback(Handler.java:587)
10-03 01:19:57.985: E/RemoteViews(739):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-03 01:19:57.985: E/RemoteViews(739):     at android.os.Looper.loop(Looper.java:123)
10-03 01:19:57.985: E/RemoteViews(739):     at android.app.ActivityThread.main(ActivityThread.java:4627)
10-03 01:19:57.985: E/RemoteViews(739):     at java.lang.reflect.Method.invokeNative(Native Method)
10-03 01:19:57.985: E/RemoteViews(739):     at java.lang.reflect.Method.invoke(Method.java:521)
10-03 01:19:57.985: E/RemoteViews(739):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-03 01:19:57.985: E/RemoteViews(739):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-03 01:19:57.985: E/RemoteViews(739):     at dalvik.system.NativeStart.main(Native Method)
lgfischer commented 9 years ago

Thank you @jimcrayne for the bug report. I did not perceived this problem while writing the example. I am not developing for Android for some time, so I will need some time until I get my Android environment running again to reproduce this problem. Please, if you solve this bug before I start working on it, I am open for pull requests.

jimcrayne commented 9 years ago

I don't want to discourage you from investigating, but I am a bit suspicious that the bug might possibly actually be some false assumptions made by the stock analog clock AppWidget that comes with the avd. At least that is a possibility to consider. I have decided against hosting appwidgets in my app, so my focus has moved elsewhere, but if it returns and I run up against this issue again, I'll keep you posted.