简体   繁体   中英

Flurry Analytics outside of Android Activity

On a current project I'm using a "helper" class to make API calls, which does not extend Activity. This helper class is called from an activity, where a Flurry session is started and stopped as suggested. Is it possible to make Flurry calls right from this helper class? I want to say yes, because the Flurry session already started as a part of the current activity, but I'm not sure.

I'd rather log the Flurry tags right when the result of the API call is received, rather than checking the result message again in the Activity, just so I don't have to duplicate some of the logic.

Will this work? Is there a better approach?

EDITED. SEE BELOW.

Thanks Jordi. I ended up using your suggestion to pass the Activity into the helper class constructor, set a local activity variable, and create a method to log the Flurry tag using the activity var.

/**
 * Logs the Flurry tag using the act that was passed into the constructor
 */

// EDITED - DON'T USE THIS ANYMORE

private void logFlurryTag(String s) {

    FlurryAgent.onStartSession(act, "XXXXXXXXXXXXXXXXXXXXX");
    FlurryAgent.logEvent(s);
    FlurryAgent.onEndSession(act);
}

I believe this should work correctly, but I haven't waited to see if the Flurry tags have started coming in yet.

*** 5-9-2012 ** *

Per spacemanaki's recommendation I decided to rework my logic to include logging the Flurry events in the activities rather than the helper classes. It really wasn't too much extra work, and I've verified the events are being reported. It also feels safer than starting and stopping the flurry session all in one method.

Your helper class and/or used method need an Activity parameter, so you can send this Activity to Flurry. Ie

Activity Class:

 Helper helper = new Helper();
 helper.helping_method(this);

Helper Class:

 public void helping_method (Activity activitat){
      FlurryAgent.onStartSession(activitat, "xxxxxxxxxxxxxxxxxx");
      FlurryAgent.onEvent("HELPING METHOD");

You can do the same when creating the Helper and save the Activity var as Class variable, to use it when needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM