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 8626535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:03:11+00:00 2026-06-12T08:03:11+00:00

Listening to the Google I/O 2012 – Doing More With Less: Being a Good

  • 0

Listening to the “Google I/O 2012 – Doing More With Less: Being a Good Android Citizen” talk, which you can see here http://www.youtube.com/watch?v=gbQb1PVjfqM&list=PL4C6BCDE45E05F49E&index=10&feature=plpp_video i found out that since api level 14 you can override onTrimMemory if you like to do some things like reducing the memory usage. But I want to implement the ComponentCallbacks2 interface outside my Activity, in my CursorAdapter for instance. In this talk it says: use Context.registerComponentCallbacks(), but when I try to use this it requires an input parameter, like this mContext.registerComponentCallbacks(ComponentCallbacks callbacks);

How can I use this?

Now I am using this

    public class ContactItemAdapter extends ResourceCursorAdapter implements ComponentCallbacks2{ 
... ...
    @Override
    public void onTrimMemory(int level) {
        Log.v(TAG, "onTrimMemory() with level=" + level);

        // Memory we can release here will help overall system performance, and
        // make us a smaller target as the system looks for memory

        if (level >= TRIM_MEMORY_MODERATE) { // 60
            // Nearing middle of list of cached background apps; evict our
            // entire thumbnail cache
            Log.v(TAG, "evicting entire thumbnail cache");
            mCache.evictAll();

        } else if (level >= TRIM_MEMORY_BACKGROUND) { // 40
            // Entering list of cached background apps; evict oldest half of our
            // thumbnail cache
            Log.v(TAG, "evicting oldest half of thumbnail cache");
            mCache.trimToSize(mCache.size() / 2);
        }
    }
}

but onTrimMemory never gets called.

  • 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-12T08:03:12+00:00Added an answer on June 12, 2026 at 8:03 am

    Since your Adapter class implements ComponentCallbacks2 already, you should be able to pass the Adapter instance as the argument to registerComponentCallbacks().

    From your activity, something like this should work:

    registerComponentCallbacks( mAdapter );
    

    After that, you should receive onTrimMemory() callbacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a simple xmpp bot in PHP which connects to google talk server.
I want to know if i can create a custom google maps application,on which
Update: I have spent more than 2 hours to google, but I can't find
I was listening to a podcast recently (may have been SO - can't remember)
I was recently listening to a podcast which made a comment on using $()
Is there a way of preventing a Google Maps (JS, v3) map being displayed
Ok, so I'm able to create a listening socket in my Android App using
What do I need to use to get a search listing using the google
It seems that, recent released Google Drive SDK supports directory listing. https://developers.google.com/drive/v2/reference/files/list I try
Im listening to my phones GPS and post latitude and longitude to my webservice

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.