【问题标题】:App Indexing for dynamic content动态内容的应用索引
【发布时间】:2016-10-13 00:24:30
【问题描述】:
我的应用有一项活动。该应用程序有一个抽屉,里面有一个从我的内容提供者那里填写的列表。用户可以从抽屉中选择一个项目,然后活动将动态填充适当的内容。我不确定在这种情况下如何实现应用索引。我的意思是based on step 3 of the tutorial,该活动似乎应该显示一个内容(我错了吗)?
注意:我已经开始进行深度链接(我有一个网站,并且内容映射到应用程序中的内容)。
具体来说,我想知道每次用户更改内容时我都会动态更改以下内容:
mUrl = "http://examplepetstore.com/dogs/standard-poodle";
mTitle = "Standard Poodle";
mDescription = "The Standard Poodle stands at least 18 inches at the withers";
如果是的话,我应该只拨打一次电话(仅在 onStart 中)。同样,我的数据是从内容提供商加载的。提供程序本身是从服务器加载的,但该调用会加载所有内容,而不是仅加载单个页面。
【问题讨论】:
标签:
android
firebase
android-app-indexing
【解决方案1】:
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);
}
}