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

  • SEARCH
  • Home
  • 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 3498340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:28:44+00:00 2026-05-18T12:28:44+00:00

I have an ExpandableListView that uses a SimpleCursorTreeAdapter which uses the cursors returned by

  • 0

I have an ExpandableListView that uses a SimpleCursorTreeAdapter which uses the cursors returned by a ContentProvider. This is fine as it always keeps in sync with the data but sometimes I need to do many changes to the database so that the cursor is requeried many times in the same second. Is it possible to suspend the notification of ContentObservers to avoid unnecessary requerys?

  • 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-05-18T12:28:45+00:00Added an answer on May 18, 2026 at 12:28 pm

    A possible solution is to modify the content provider to allow suspending notifications. URIs to be notified are added to a queue until suspension is disabled.

    private boolean suspendNotifications = false;
    private LinkedList<Uri> suspendedNotifications = new LinkedList<Uri>();
    private HashSet<Uri> suspendedNotificationsSet = new HashSet<Uri>();
    
        private void notifyChange(Uri uri) {
        if (suspendNotifications) {
            synchronized (suspendedNotificationsSet) { // Must be thread-safe
                if (suspendedNotificationsSet.contains(uri)) {
                    // In case the URI is in the queue already, move it to the end.
                    // This could lead to side effects because the order is changed
                    // but we also reduce the number of outstanding notifications.
                    suspendedNotifications.remove(uri); 
                }
                suspendedNotifications.add(uri);
                suspendedNotificationsSet.add(uri);
            }
        }
        else {
            getContext().getContentResolver().notifyChange(uri, null);
        }
    }
    
    private void notifyOutstandingChanges() {
        Uri uri;
        while ((uri = suspendedNotifications.poll()) != null) {
            getContext().getContentResolver().notifyChange(uri, null);
            suspendedNotificationsSet.remove(uri);
        }
    }
    
    private void setNotificationsSuspended(boolean suspended) {
        this.suspendNotifications = suspended;
        if (!suspended) notifyOutstandingChanges();
    }
    
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        ...
        notifyChange(uri);
        return newItemUri;
    }
    

    I’m not sure how to best enable/disable suspension but one possibility would be to have a special URI which turns on/off suspension (e.g. content://<authority>/suspension) in the update() method:

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        switch (uriMatcher.match(uri)) {
        ...
        case SUSPEND:
            boolean enabled = values.getAsBoolean("enabled");
            setNotificationsSuspended(enabled);
            break;
        ... 
        }
    }
    

    The service that does the changes to the database can now suspend the ContentProvider when it starts and disable suspension when it finishes.

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

Sidebar

Related Questions

Here is what I'm working with: I have an ExpandableListView that uses a SimpleCursorTreeAdapter
Im trying to implement an activity that uses ExpandableListView and I have gotten so
If I want to have an ExpandableListView, which gets data from a response from
I need a working example of an application that uses an expandableListView. I have
have written this little class, which generates a UUID every time an object of
can we have ExpandableListView inside ListView so that I can have group level first
I have a ExpandableListView in which i am loading custom layouts in both group
I have an ExpandableListView with children that have text supplied on creation, and an
Hello i have a simple expandable list activity that was working fine until i
I have an ExpandableListView . The xml for the Child rows looks like this:

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.