2016-06-12 28 views
5

我的應用有一項活動。該應用程序有一個抽屜,其中有一個由我的內容提供商填充的列表。用戶可以從抽屜中選擇一個項目,然後動態地填充相應的內容。我不確定如何在這種情況下實施應用程序索引。我的意思是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只要)。再次,我的數據從內容提供者加載。提供程序本身是從服務器加載的,但該調用會加載所有內容 - 與加載單個頁面相反。

+0

嘗試此鏈接,這可能會幫助我猜https://firebase.google.com/docs/dynamic-links/android#handle-deep-links –

回答

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); 
    } 
}