I am trying a write an app widget to display some info during the day from 8am to 8pm. Right before 8am, it restarts from fresh. After 8pm, it stops its processing. I use a widget provider and a configurator.
I almost completed the whole thing. The display has no problem. For the restart in the morning, I use the original intent of the configurator, put an extras to store the original widget id, put the intent in a pending intent and set an alarm to fire the pending intent to the configurator again for the restart. The configurator uses the saved widget id to refresh the widget display at 8am. This part works too.
However, if during the day I remove the widget from HOME and re-drag it to HOME again, the widget display still worked well but the morning refresh didn't. I did a lot of logging and here is what I found:
1. First time after install drag the widget to HOME, widget id in the intent was 27, configurator saved 27 to the extras of the intent and set alarm with the same intent to be fired at 7:55am tomorrow
2. widget worked well, stoped display at 8pm as expected
3. At 7:55am alarm fired, configurator got an intent with widget id (27) and refresh the widget display correctly
4. widget worked well, I removed the widget from HOME and re-drag it to HOME again
5. configurator started with widget id 28, widget (should be a different instance from the above, I think) still worked well
6. widget (id 28) stoped display a 8pm as expected
7. At 7:55am alarm fired, but this time configurator got an intent with widget id 27
, widget (id 28) doesn't refresh because the widget id is incorrect
What I don't understand is why the original intent, the one that carries widget id 27 is still around (although my log showed that onDeleted and onDisabled had been called) and why it gets into Step 7 above. I didn't include my coding here because I may misunderstand how app widget works and I want to straight out this point first. Please help.
I almost completed the whole thing. The display has no problem. For the restart in the morning, I use the original intent of the configurator, put an extras to store the original widget id, put the intent in a pending intent and set an alarm to fire the pending intent to the configurator again for the restart. The configurator uses the saved widget id to refresh the widget display at 8am. This part works too.
However, if during the day I remove the widget from HOME and re-drag it to HOME again, the widget display still worked well but the morning refresh didn't. I did a lot of logging and here is what I found:
1. First time after install drag the widget to HOME, widget id in the intent was 27, configurator saved 27 to the extras of the intent and set alarm with the same intent to be fired at 7:55am tomorrow
2. widget worked well, stoped display at 8pm as expected
3. At 7:55am alarm fired, configurator got an intent with widget id (27) and refresh the widget display correctly
4. widget worked well, I removed the widget from HOME and re-drag it to HOME again
5. configurator started with widget id 28, widget (should be a different instance from the above, I think) still worked well
6. widget (id 28) stoped display a 8pm as expected
7. At 7:55am alarm fired, but this time configurator got an intent with widget id 27
, widget (id 28) doesn't refresh because the widget id is incorrectWhat I don't understand is why the original intent, the one that carries widget id 27 is still around (although my log showed that onDeleted and onDisabled had been called) and why it gets into Step 7 above. I didn't include my coding here because I may misunderstand how app widget works and I want to straight out this point first. Please help.