Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:38:26+00:00 2026-06-02T14:38:26+00:00

I am developing an app that uses a kind of local background. The idea

  • 0

I am developing an app that uses a kind of local background. The idea is to make this changable. I manage to change the “background” using this code.

Bitmap bMap = BitmapFactory.decodeFile(sharedPreferences.getString("PICTURE", ""));
        Drawable d =new BitmapDrawable(bMap);
        bac.setBackgroundDrawable(d);
        } 

The problem is that each time i return to the “background screen” the app crashes because of OutOfMemoryError. Then it shows the new background. I need some sort of code that makes that the app does not crash. I manage to this in a ImageView but not in LinearLayout. For ImageView I use this code:

Bitmap bMap = BitmapFactory.decodeFile(sharedPreferences.getString("PICTURE", ""));
    image.setImageBitmap(bMap);

And to avoid it from crashing:

@Override
protected void onPause() {
super.onPause();

unbindDrawables(findViewById(R.id.iv_pic));
System.gc();

}

private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
    view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
        unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
    ((ViewGroup) view).removeAllViews();
    }
}
@Override
protected void onDestroy() {
super.onDestroy();

unbindDrawables(findViewById(R.id.iv_pic));
System.gc();

}

How do I do the same for a LinearLayout?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:38:29+00:00Added an answer on June 2, 2026 at 2:38 pm

    There are a lot of questions asked on SO about the OOM exception and how to deal with it. Please search the forum before posting a question.

    Some notes:

    1. You can release the memory consumed by a Bitmap using the recycle method (in your code, you can call bMap.recycle())
    2. You can retrieve the reference to your LinearLayout using findViewById and pass that to the unbindDrawables like unbindDrawables(findViewById(R.id.myLinearLayoutId));
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing an app that uses Core Data. I'm using two stores/configurations, one
I´m developing an ASP.NET MVC app that uses EF 4.1 Code First. I have
I'm on developing iphone app that uses backend web service(django). To login the web
I'm learning MVVM with the hope of developing an app that uses the phone's
I'm developing an Android app that uses Osmdroid to display the maps in offline
I've been developing an iPhone app that uses a UIToolbar (in the context of
I'm developing an app in Visual C++ that uses an SQLite3 DB for storing
i'm developing an app that make requests to the Musicbrainz webservice. I read in
I'm developing an app that uses iOS4 features (like MFMessageComposeViewController), but I want to
I'm thinking of developing an app that uses Microsoft Push Notification. However, I'm not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.