Search code examples
androidandroid-asynctaskandroid-contentprovider

Android;use "ContentProvider" to download from web server


Is it possible to use ContentProvider for retrieving(query) data from web server?

Some data that are used in App are stored locally and some others stored in web server,I want to encapsulate retrieving data and also storing data by ContentProvider.

Obviously retrieving local data is simple and may be done by ContentProvider.query() method.My problem is in about use that method to query from web.Clearly I can start AsyncTask to fetch data from web,but result returned from query method,before terminating doInBackground() of AsyncTask and downloaded data never used.

So how can I return downloaded data to query method?


Solution

  • Is it possible to use ContentProvider for retrieving(query) data from web server?

    No.

    So how can I return downloaded data to query method?

    you can not remove the delay of downloading obviously but you can use for example loader and after your data is ready(downloaded) insert it to the database and call

    getContentResolver().notifyChange(your uri, null);
    

    or you can use other method like LocalBroadcastManager or EventBus for sending messages to your object to query the ContentProvider again.