Android: call custom methods in a ContentProvider

萝らか妹 提交于 2019-11-28 10:55:58

But I am not able to call my custom method (FixesContentProvider#getLastFix).

That's completely true. In this very case though, you can take advantage of one fact: both query and getLastFix methods return a Cursor object. So, what I do would be adding some value to the URI that you pass to query and, then decide what you want to actually do: query or getLastFix. For instance:

public Cursor query(Uri uri,...) { 
    if ( uri says it has to return the last fix )
        return getLastFix(uri);
    // otherwise, do normal operations...
    return cursor;
}

In fact, the query method is suppose to return a result, given a Uri. So, if you need to retrieve the last fix, you have to specify in the URI that you want the last fix.

As of API level 11 there is a method ContentResolver.call(Uri, String, String, Bundle) which provides extra flexibility.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!