AFAIK, you must connect your GoogleApiClient once per activity. However, you can index your dynamic content as much as you want (but itβs better not to index the content too many times), just remember to turn them off when your activity ends. The following is what I did in my project:
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 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 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); } }
source share