Technical record of Android widget Development

Source: Internet
Author: User

1. Data to be displayed in the widget UI is stored in the provider as static variables.

I discussed with my colleagues the feasibility of the other two solutions:
A. enable the Service to retrieve data. The data is stored in the service as static variables.
B. stored locally.
The quality of these three solutions lies in the fact that one thing is the lifecycle of static variables. In terms of Linux memory management, processes in the memory will not be released as long as the memory is insufficient. Also, after the client is started once, static variables exist as long as the memory is not full. After this conclusion is obtained, we can see that the data is stored in the provider and service in the form of static variables, and the result is the same (the premise is that the service is not open in the Application
).
However, theoretically, the client may be squeezed out of the memory, and the widget data is lost. This reflects the superiority of solution B, and data always exists. However, the only drawback of solution B is that it needs to be retrieved locally each time, and the speed is flawed.

2. Where can I enable the thread to obtain data?

Do you want to open a service or simply enable a thread when update is required in onupdate of provider? The conclusion is that the results are the same as long as the service does not open the process. Because their lifecycles are all application lifecycles in the memory, it is inconvenient to exchange data with widgets when using services.

3. You can use the appwidgetmanager generated by the current context to update the UI. Do not save the context. Wait until the internet gets the data and use it to generate appwidgetmanager to update the UI. This means the update is unsuccessful.

4. Call New remoteviews twice and pass in the same viewid. The view tree in the remoteviews obtained for the second time is the same as that in the first time. Currently, there is no solution. You can only reset it first to clear the last UI data, but not pendingintent. You can set an empty pendingintent to achieve no response.
Intent intent = new intent ();
Return pendingintent. getbroadcast (context, 0, intent, 0 );

5. When the static variable storage ID is used, once the client is abnormal and the process crashes, the ID is lost. In this way, the UI data on the widget is not updated even if you log on to the background again without the ID information. Therefore, the UI data can be stored in static variables, and can be retrieved again after the process crashes and restarts, but the ID information must be stored locally. For example, sharedpreference should not be retrieved every time it is updated, so that the update will be very slow. You can check whether there is no ID information each time. If there is no ID information, you can obtain it locally. In addition, each time the system calls onupdate and ondeleted, It synchronizes the local ID information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.