简体   繁体   English

Android活动之外的Flurry Analytics

[英]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. 在当前项目中,我正在使用“帮助程序”类进行API调用,这不会扩展Activity。 This helper class is called from an activity, where a Flurry session is started and stopped as suggested. 从活动中调用此帮助程序类,在该活动中,按照建议启动和停止Flurry会话。 Is it possible to make Flurry calls right from this helper class? 是否可以直接从此帮助程序类进行Flurry呼叫? I want to say yes, because the Flurry session already started as a part of the current activity, but I'm not sure. 我想说是,因为Flurry会话已经作为当前活动的一部分开始了,但是我不确定。

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. 我宁愿在收到API调用的结果时立即记录Flurry标签,而不是在Activity中再次检查结果消息,只是这样,我不必重复某些逻辑。

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. 我最终根据您的建议将Activity传递给了帮助器类的构造函数,设置了一个本地activity变量,并创建了一个使用activity var记录Flurry标签的方法。

/**
 * 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. 我相信这应该可以正常工作,但是我还没等过Flurry标签是否已经开始使用。

*** *** 5-9-2012 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. 根据spacemanaki的建议,我决定重做我的逻辑,包括在活动中而不是在帮助程序类中记录Flurry事件。 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. 您的助手类和/或使用的方法需要一个Activity参数,因此您可以将此Activity发送给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. 您可以在创建Helper时执行相同的操作,并将Activity var保存为Class变量,以在需要时使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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