当我将flurry代码添加到我的活动中时崩溃说flurry sdk没有初始化,我已经检查以确保库已添加到项目库中,下面是我的代码和logcat,它还有活动中的导入乱码
@Override
protected void onStart() {
super.onStart();
FlurryAgent.onStartSession(this,"YOUR_API_KEY" );
FlurryAgent.setLogEnabled(true);
FlurryAgent.setLogEvents(true);
FlurryAgent.setLogLevel(Log.VERBOSE);
}
@Override
protected void onStop() {
super.onStop();
FlurryAgent.onEndSession(this);
}
Run Code Online (Sandbox Code Playgroud)
logcat的
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stephenh.daytrack.daytrackstephenh/com.stephenh.daytrack.daytrackstephenh.PageActivities.Exercises}: java.lang.IllegalStateException: Flurry SDK must be initialized before starting a session
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2263)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5212)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Flurry SDK must be initialized before starting a session
at com.flurry.android.FlurryAgent.onStartSession(SourceFile:328)
at com.stephenh.daytrack.daytrackstephenh.PageActivities.Exercises.onStart(Exercises.java:61)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1172)
Run Code Online (Sandbox Code Playgroud)
Sri*_*h P 17
它的崩溃因为FlurryAgent没有初始化而你正在尝试启动会话.所以,像这样初始化FlurryAgent:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// configure Flurry
FlurryAgent.setLogEnabled(false);
// init Flurry
FlurryAgent.init(this, MY_FLURRY_APIKEY);
}
}
Run Code Online (Sandbox Code Playgroud)
稍后您可以启动和停止会话,如下所示:
@Override
protected void onStart()
{
super.onStart();
FlurryAgent.onStartSession(this, "YOUR_API_KEY");
}
@Override
protected void onStop()
{
super.onStop();
FlurryAgent.onEndSession(this);
}
Run Code Online (Sandbox Code Playgroud)
FlurryAgent.onStartSession(context, key);不推荐使用该方法需要先调用方法FlurryAgent.init(context, key);然后调用FlurryAgent.onStartSession(context);
| 归档时间: |
|
| 查看次数: |
4602 次 |
| 最近记录: |