gpt4 book ai didi

android - 传递 ContentResolver 有风险吗?

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

我的申请有 3 个要素:1. UI( Activity )2.模型(类)3. content provider——提供来自数据库的数据

为了让模型类访问来自内容提供者的数据,我需要 UI( Activity )向它传递一个 ContentResolver - 这样我就可以在模型类中创建一个游标:

        cursor = mContentResolver.query(
MyobiliseData.CONTENT_URI_RUNSUMMARY, // The content URI of the words table
projection, // The columns to return for each row
selectionClause, // Selection criteria
selectionArgs, // Selection criteria
null); // The sort order for the returned rows

这是可以接受的做法,还是有更好的方法从非 Activity 类调用内容提供者?

谢谢

安东

最佳答案

Activity提供context给其他类,然后使用context通过context getter方法获取各种对象,包括getContentResolver(),这是一种常见的模式。例如,参见 How can I call getContentResolver in android? 的答案

关于android - 传递 ContentResolver 有风险吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11032024/

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