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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:51:54+00:00 2026-06-11T05:51:54+00:00

I have a content provider in on apk which is providing Rest Based Search

  • 0

I have a content provider in on apk which is providing Rest Based Search results for multiple client apps.

Basically, the client requests a cursor via content resolver, then fires an intent service request to trigger the search..

In the provider, the cursor is returned to a table, and each intent service request populates the corresponding table, and triggers a NotifyDataSetChanged.

Works really well.. The only issue I am having is that if the Provider is killed for some reason (tested by doing pkill -9 com.myprovider.name) the cursor on the client apk does not change, but the app is not notified that the provider went away, and would need to re-connected to the db.. So it will continue to fire off service intents, and the cursor never gets updated b/c it is no longer tied to the underlying db..

I went through our code to try and see if we were catching some exceptions, that maybe hiding the underlying issue, but I am not seeing it..

I tried explicitly doing a cursor.close() in the provider in finalize / onLowMemory / shutdown().. None appear to get triggered.

I noticed that this happens in the logcat

09-10 13:58:03.015: I/ActivityThread(4268): Removing dead content provider: com.myprovider.name (called from the calling app)

Any way to get this notification from the calling app?

  • 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-11T05:51:55+00:00Added an answer on June 11, 2026 at 5:51 am

    So after some research, I have a workable solution, but would if anyone has any other suggestions, they would be appreciated.

    Due to the fact we are using a contentProvider to get a cursor, then just updating the back end data via IntentService. We grab the cursor when our user types the first character in of their search, if the cursor count = 0, then we show an empty list message, otherwise we display the list of items in that cursor..

    ** NOTE: Some of the cursor handling may need to be tweaked a bit, I did not see any crashes w/ our Adapter having a cursor ripped out and becoming null, but your mileage may vary.. ( This is more about using the contentProviderClient() )

    ** NOTE: Per the documentation, you MUST release the contentProviderClient() when not in use anymore.

    Since a content provider should be returning a type, we can do the following..

    So we define a member variable

    private ContentProviderClient contentProviderClient = null;
    

    Then when our user changes the search string we end up calling

    public void setFilter( String searchFilter ) {
       searchedString = !TextUtils.isEmpty(filter) ? filter : "";
    
       boolean reload = false;               // Reloads content provider
    
       // contentProvider is null on first connection, assumed to be up on 
       // subsequent connections as we only close the cursor and 
       // contentProviderClient when we exit
    
       if (contentProviderClient != null) {
          try {
          // getType will throw an exception if the instance of the 
          // contentProvider went away (killed by user/memory collection etc)
    
             contentProviderClient.getType(searchFactoryUri);
          } catch (RemoteException e) {
             if( searchAdapter != null ) {
                Cursor cursor = searchAdapter.getCursor();
                cursor = null; 
                reload = true;
                contentProviderClient.release();
             }
          }
       }
    
       // This is for first search initialization or reloading cursor 
       // if the content provider went away for some unknown reason.
    
       if( this.searchAdapter == null || reload ){
          Cursor cursor = getActivity().getContentResolver().query(
                MY_URI,
                null,
                null,
                null,
                null);
    
       contentProviderClient = getActivity()
                 .getContentResolver()
                 .acquireContentProviderClient(MY_URI);
    
       cursor.setNotificationUri(getActivity.getContentResolver(), MY_URI);
    
       // DO what ever you need to after getting cursor, a cursor loader
       // would be a better implementation here, but simplifying it as 
       // I don't want to over-complicate the example.
    
       myList.setAdapter(searchAdapter);
    
       }
       getActivity().startService(MyUtil.getSearchIntent( MY_URI, searchedString );
    }
    
    @Override
    public void onDestroy() {
       super.onDestroy();
       // Cleanup adapter, cursor, provider client
       if (searchAdapter != null) {
          searchAdapter.changeCursor(null); // Closes existing cursor 
       }
       if (contentProviderClient != null) {
         contentProviderClient.release();  // Release client
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own custom Content Provider that loads a database which contains the
In my application I have a content provider which uses a database for the
I have two applications which use the same content provider, but I can't put
I have to get a part of my content provider query in a String[]
I have content on a webpage which is both sent from the server at
I have a content provider that is custom to my set of Android applications,
I need to get the id of a content provider that is providing me
I have a custom content provider and I need to insert one record at
I have an AsyncTask that queries a content provider and does some additional processing
I have an .apk application for android which has been compiled and packed with

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.