Launcher3 custom wallpaper cannot be restored after being stretched after rotation

Source: Internet
Author: User

Mtk8382/8121 platform.

 

Description: After setting a custom image as a wallpaper, the portrait screen is rotated when the screen is displayed. The image is stretched because the resolution is too small. The image is then rotated to the landscape screen without restoration.

This problem has been solved in the past two days. It has been studied for a long time and has taken many detours. Finally, it was found that the launcher had a bug in reading sharepreferences.

 

The bug is generated as follows:

When the custom wallpaper is set in launcher3 (the built-in wallpaper is not recorded. android. launcher3.wallpapercropactivity. record the resolution of the wallpaper set in XML, and submit the resolution to wallpapermanager (via suggestwallpaperdimension ()). The specific function is: updatewallpaperdimensions () in wallpapercropactivity. Java, which is called by setwallpaper () of wallpapercropactivity. Java;

Launcher3 re-executes oncreate () after each rotation, and submits the resolution of the current wallpaper to wallpapermanager. The resolution submission function is in setwallpaperdimension () In workspace. java. The problem is that setwallpaperdimension () cannot get the sharedpreferences modified by updatewallpaperdimensions (). As a result, it submits the default wallpaper resolution of 1920x1080, resulting in low-resolution wallpaper stretching.

To solve this problem, modify the flag of getsharedpreferences () in setwallpaperdimension () In workspace. Java and change mode_private to mode_multi_process. After modification, access is successful.

 

My problem is:

According to Android developer's explanation:

Mode_private:

File Creation Mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID ).

That is, model_private can only be called by the same application or application with the same userid. In this case, the two activities can be accessed together. (Workspace. Java uses the context of launcher. java. The two activity PIDs are different, and the UID is the same)

At the same time, I also read the explanation of mode_multi_process:

Mode_multi_process:

Sharedpreference loading flag: When set, the file on disk will be checked for modification even if the shared preferences instance is already loaded in this process. this behavior is sometimes desired in cases where the application has multiple processes, all writing to the same sharedpreferences file. generally there are better forms of communication between processes, though.

This was the legacy (but untitled ented) behavior in and before gingerbread (Android 2.3) and this flag is implied when targetting such releases. For applications targetting SDK versionsGreaterAndroid 2.3, this flag must be explicitly set if desired.

This flag is used to allow applications with multiple processes to access the same sharedpreferences. It seems that model_multi_process should be used again.

 

So I want to find the getsharedpreference implementation code and see how it handles these flags. We can't find the implementation method from the parent class level of the activity until we find this article:

Http://blog.csdn.net/qinjuning/article/details/7310620

To know how contextimpl implemented context, and then found the answer:

The contextimpl class has the getsharedpreferences implementation. It indicates that in the mode_multi_process flag, getsharedpreferences performs reload. In other words, mode_private will not re-read sharedpreferences.

Here, I finally understood what he meant: In the previous bug, it was not because sharedpreferences failed to be obtained, but because there was no reload, so I didn't get the resolution information of the new write. Because I didn't notice this problem before, I took a detour.

Launcher3 custom wallpaper cannot be restored after being stretched after rotation

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.