Android Question Update widget when phone configuration change

Discussion in 'Android Questions' started by ducphu, Mar 4, 2015.

  1. ducphu

    ducphu Active Member Licensed User

    Hi all,

    I have a widget which data is drew using canvas. I already know that in some cases, when phone configuration is changed, the widget data is lost and I need to update it (for example, when phone is rotated)

    In my app, I used broadcastreceiver to catch screen rotation event using "android.intent.action.CONFIGURATION_CHANGED"

    I want to ask, is there any other phone changes in which I need to update my widget also? maybe changing of theme or any phone settings...?? If there is, can anyone tell me which intent is corresponded to that event also?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    I'm not familiar with any other relevant intent. However do note that the event will only be raised if the process is running as this is not a static intent (and you cannot use a static intent here). It is probably worth making the service a sticky service.
     
  3. ducphu

    ducphu Active Member Licensed User

    Yes, I declare my service as sticky service. I ask abt this because I randomly encounter that my widget loses its data but still not manage to find out which causes it..
     
  4. ducphu

    ducphu Active Member Licensed User

  5. Erel

    Erel Administrator Staff Member Licensed User

    I don't see how this solution will behave differently. If Android kills your process the home hosting app is supposed to later restart the process to allow the widget to be updated.
     
  6. ducphu

    ducphu Active Member Licensed User

    Ok. But the issue with my widget is that I set it to be updated once a day. If the widget data is lost, it means that it can only get back the data next day. Anyway, the most headache here is I don't know what can cause this to happen.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Set it to update every 30 minutes. If Service_Create was fired then the process was previously killed and you need to update the widget. If only Service_Start is raised then the process was running. In that case update the widget only if more than 24 hours have passed since the last update.
     
  8. ducphu

    ducphu Active Member Licensed User

    Hi Erel but sorry I don't get what you mean. My widget basically displays a calendar. The data is sent to widget using canvas draw, at time of creation and is updated daily. In my rv_RequestUpdate sub, after finish updating, I put a StopService("") command. So basically, during the day, my service is not running at all. I only startup the service to update my widget in 2 cases, either by schedule (daily) or when "android.intent.action.CONFIGURATION_CHANGED" is raised ( I have another sticky service to monitor this)

    When my widget loses its data, it becomes a blank widget, i.e the background is still there but all the numbers, texts.. drew using canvas are gone. This happens like before I used broadcastreceiver to capture when the phone is rotated. That's why I think of, maybe some other intents are being raised
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    I'm trying to find an alternative solution. Android can kill the process from time to time.

    If you have another sticky service then it doesn't matter whether you call StopService or not.

    Don't call StopService and change the widget update interval to 30 minutes. This way you can minimize the impact of this issue.
     
  10. ducphu

    ducphu Active Member Licensed User

    I think even if I leave the service running, it doesn't help if this issue is caused by an intent as it doesn't call rv_RequestUpdate.
    Yes, I may change the update interval to 30mins but it is not really a good solution as in the worst case, it may take 30mins until my widget is recovered, and, during that 30mins, my widget is dead...which is unacceptable to the customer. Really hope that we can have a better solution for this.

    Btw, what do you think is the cause of this issue? I dont see how "Android can kill the process from time to time" cause this issue, as my widget doesn't have any real time, continuous data tranfer with any process...
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    The launcher, which hosts the widgets, is expected to restart your widget process automatically. I don't know why it doesn't happen in this case.
     
  12. ducphu

    ducphu Active Member Licensed User

    humm but can you tell me what is the mechanism behind this? In which case or which event that the launcher will restart widget process? Sorry for my noob :(
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    As I wrote I do not know why this launcher doesn't restart your process. It should happen automatically.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice