gpt4 book ai didi

android - ContentProviderClient release() 弃用

转载 作者:太空狗 更新时间:2023-10-29 16:29:51 25 4
gpt4 key购买 nike

我找到了一些删除数据库并使用 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();

但是在 ContentProviderClient 类中有 release()deprecated,有没有其他方法可以释放资源。

编辑:如果我尝试使用 close(),它会显示如下警告。

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.

close()显示为禁用,为什么?

enter image description here

最佳答案

如果有人想知道代码应该是什么:

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

关于android - ContentProviderClient release() 弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42264803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com