Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Indexing for dynamic content

My app has one activity. The app has a drawer that has a list that is filled from my content provider. From the drawer the user can select an item and then the Activity will be filled with the appropriate content dynamically. I am not sure how to implement app indexing in such a case. I mean based on step 3 of the tutorial, the activity seems to be expected to show one content (am I wrong about this)?

Note: I already got deep linking working ( I have a website and the content map to the content in the app).

Specifically I am wondering to I dynamically change the following each time the user changes the content:

    mUrl = "http://examplepetstore.com/dogs/standard-poodle";
    mTitle = "Standard Poodle";
    mDescription = "The Standard Poodle stands at least 18 inches at the withers";

And if yes, how about the fact that I am only supposed to make the call once (in onStart only). And again, my data is loaded from a content provider. The provider itself is loaded from the server, but that call loads everything -- as opposed to just loading a single page.

like image 342
Katedral Pillon Avatar asked Oct 18 '22 07:10

Katedral Pillon


1 Answers

AFAIK, you should connect your GoogleApiClient once per activity only. However, you can index your dynamical content as much as you want (but better to not index content too many times), just remember to disconnect them when your activity finish. Below 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'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);
    }
}
like image 62
Kingfisher Phuoc Avatar answered Oct 21 '22 05:10

Kingfisher Phuoc