动态内容的应用索引
问题描述:
我的应用有一项活动。该应用程序有一个抽屉,其中有一个由我的内容提供商填充的列表。用户可以从抽屉中选择一个项目,然后动态地填充相应的内容。我不确定如何在这种情况下实施应用程序索引。我的意思是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只要)。再次,我的数据从内容提供者加载。提供程序本身是从服务器加载的,但该调用会加载所有内容 - 与加载单个页面相反。
答
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);
}
}
尝试此链接,这可能会帮助我猜https://firebase.google.com/docs/dynamic-links/android#handle-deep-links –