Search code examples
androidandroid-contentproviderandroid-contentresolvercontentproviderclient

ContentProviderClient release() deprecated


I found some solution to delete database and recreate it using ContentProvider.

        ContentResolver resolver = mContext.getContentResolver();
        ContentProviderClient client = resolver.acquireContentProviderClient(KOOPSContentProvider.AUTHORITY);

        assert client != null;
        KOOPSContentProvider provider = (KOOPSContentProvider) client.getLocalContentProvider();

        assert provider != null;
        provider.resetDatabase();

        client.release();

but in that ContentProviderClient class has release() which is deprecated, Is there any other way to free up resources.

Edited: If I try to use close(), It is displaying as warning as follow.

This ContentProviderClient should be freed up after use with #release().

Many resources, such as TypedArrays, VelocityTrackers, etc., should be recycled (with a recycle() call) after use. This lint check looks for missing recycle() calls.

and close() displaying as disabled, why?

enter image description here


Solution

  • in case anyone is wondering what the code should be:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
    {
        client.close();            
    }
    else
    {
        client.release();
    }