Flurry SDK will not initialize when starting a session

when I add an expansion code to my activity, it gives a message that flurry sdk has not been initialized, checked by ive to make sure that the library is added to the project library, below is my code and logcat, it also has a flurry of imports into activity

@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);
}

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)
+4
source share
3 answers

Failure because FlurryAgent is not initialized and you are trying to start a session. So, initialize FlurryAgent as follows:

public class MyApplication extends Application {

   @Override
   public void onCreate() {

   super.onCreate();

   // configure Flurry
   FlurryAgent.setLogEnabled(false);

   // init Flurry
   FlurryAgent.init(this, MY_FLURRY_APIKEY);
 }
}

Later you can start and stop the session as shown:

    @Override
    protected void onStart()
{
    super.onStart();
    FlurryAgent.onStartSession(this, "YOUR_API_KEY");
}

@Override

protected void onStop()
{
    super.onStop();     
    FlurryAgent.onEndSession(this);
}
+17
source

The method is FlurryAgent.onStartSession(context, key);deprecated, you need to call the method first FlurryAgent.init(context, key);and afterFlurryAgent.onStartSession(context);

+4

I ran FlurryAgent.init(this, "myapikey");Activity in my startup, and I got an exception in onStartmy follow-up.

So, I just called FlurryAgent.init(this, "myapikey");. No problem, as of now.

0
source

Source: https://habr.com/ru/post/1568194/


All Articles