Search code examples
androidflurry

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?


Solution

  • 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.