应用程序索引动态内容

Kat*_*lon 5 android firebase android-app-indexing

我的应用有一项活动.该应用程序有一个抽屉,其中包含一个从我的内容提供商处填写的列表.用户可以从抽屉中选择一个项目,然后动态地用适当的内容填充活动.我不确定如何在这种情况下实现应用程序索引.我的意思是根据教程的第3步,活动似乎预计会显示一个内容(我错了吗)?

注意:我已经有深层链接工作(我有一个网站和内容地图到应用程序中的内容).

具体来说,我想知道每次用户更改内容时我都会动态更改以下内容:

    mUrl = "http://examplepetstore.com/dogs/standard-poodle";
    mTitle = "Standard Poodle";
    mDescription = "The Standard Poodle stands at least 18 inches at the withers";
Run Code Online (Sandbox Code Playgroud)

如果是的话,我应该只进行一次调用(仅在onStart上).同样,我的数据是从内容提供商加载的.提供程序本身是从服务器加载的,但是该调用加载了所有内容 - 而不是仅加载单个页面.

Kin*_*uoc 3

AFAIK,每个活动您应该GoogleApiClient只连接一次。但是,您可以根据需要对动态内容建立索引(但最好不要对内容建立索引太多次),只需记住在活动完成时断开它们即可。以下是我在项目中所做的:

HashMap<String, Action> indexedActions;
HashMap<String, Boolean> indexedStatuses;
public void startIndexing(String mTitle, String mDescription, String id) {
    if (TextUtils.isEmpty(mTitle) || TextUtils.isEmpty(mDescription))
        return; // dont index if there's no keyword
    if (indexedActions.containsKey(id)) return; // dont try to re-indexing
    if (mClient != null && mClient.isConnected()) {
        Action action = getAction(mTitle, mDescription, id);
        AppIndex.AppIndexApi.start(mClient, action);
        indexedActions.put(id, action);
        indexedStatuses.put(id, true);
        LogUtils.e("indexed: " + mTitle + ", id: " + id);
    } else {
        LogUtils.e("Client is connect : " + mClient.isConnected());
    }
}

public void endIndexing(String id) {
    // dont endindex if it's not indexed
    if (indexedStatuses.get(id)) {
        return;
    }
    if (mClient != null && mClient.isConnected()) {
        Action action = indexedActions.get(id);
        if (action == null) return;
        AppIndex.AppIndexApi.end(mClient, action);
        indexedStatuses.put(id, false);
    }
}
Run Code Online (Sandbox Code Playgroud)