Launcher App: "OutOfMemoryError: bitmap size exceeds VM budget" is generated when the wallpaper is too large"

Source: Internet
Author: User

An OOM error occurs when you view the preview of a large wallpaper image on the main screen because the wallpaper image is too large.

 

Exception prompt:

 

E/inputmanagerservice (177): Got RemoteException sending setactive (false) Notification
E/inputmanagerservice (177): Android. OS. deadobjectexception
E/inputmanagerservice (177): at Android. OS. binderproxy. transact (native method)
E/inputmanagerservice (177): At com. Android. Internal. View. iinputmethodclient $ stub $ proxy. setactive (iinputmethodclient. Java: 158)
E/inputmanagerservice (177): At com. Android. server. inputmethodmanagerservice. unbindcurrentinputlocked (inputmethodmanagerservice. Java: 554)
E/inputmanagerservice (177): At com. Android. server. inputmethodmanagerservice. startinputlocked (inputmethodmanagerservice. Java: 616)
E/InputManagerService (177): at com. android. server. InputMethodManagerService. startInput (InputMethodManagerService. java: 700)
E/InputManagerService (177): at com. android. internal. view. IInputMethodManager $ Stub. onTransact (IInputMethodManager. java: 113)
E/InputManagerService (177): at com. android. server. InputMethodManagerService. onTransact (InputMethodManagerService. java: 466)
E/InputManagerService (177): at android. OS .Binder.exe cTransact (Binder. java: 276)
E/InputManagerService (177): at dalvik. system. NativeStart. run (Native Method)

 

Code Section:

 

Public class com. android. launcher. WallpaperChooser

@ Override
Public void onCreate (Bundle icicle ){
Super. onCreate (icicle );
RequestWindowFeature (Window. FEATURE_NO_TITLE );

FindWallpapers ();

SetContentView (R. layout. wallpaper_chooser );

MOptions = new BitmapFactory. Options ();
MOptions. inDither = false;
MOptions. inPreferredConfig = Bitmap. Config. ARGB_8888;
MOptions. inSampleSize = 2; // fix it
......

 

Public void onItemSelected (AdapterView parent, View v, int position, long id ){
Final ImageView view = mImageView;
Bitmap B = BitmapFactory. decodeResource (getResources (), IMAGE_IDS [position], mOptions); // here throw the OOMError

......

 

Solution:

 

1. Adjust merory useage

 

MOptions. inSampleSize = 2; // return an image that is 1/2 the width/height of the original, and 1/4 the number of pixels.

 

2. Adjust bitmap size

 

Bitmap = Bitmap. createScaledBitmap (bitmap, 100,150, false );

 

3. Adjust temp storage

 

MOptions. inSampleSize = new byte [100*1024];

 

Reference: http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue

 

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.