user4301080
user4301080

Reputation:

Flurry SDK wont initialise on session start

when i add the flurry code into my activity it crashes saying flurry sdk not initialised, ive checked to make sure that the library is added to the project library, below is my code and logcat, it also has the import flurry in the 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)

Upvotes: 4

Views: 4933

Answers (4)

Wraithious
Wraithious

Reputation: 395

Since the last couple of Flurry updates to comply with GDPR they have depreciated the init function, and SDK jar files as well. You can now init flurry by just implementing the FlurryAgent.Builder class. Since jar files are depreciated and will be removed soon you now should inject the dependency into your apps build gradle file.

Example of build gradle injection (use 11.1.0 or higher sdk, don't use sdk 11.0.0 because it was bugged with an initialization with an activity context error)

repositories {
jcenter()
google()
}
dependencies {

implementation 'com.flurry.android:analytics:11.1.0@aar'
implementation 'com.flurry.android:ads:11.1.0@aar'
implementation 'com.google.android.gms:play-services:12.0.1'
}

And here is an example of using the FlurryAgent.Builder to init Flurry:

new FlurryAgent.Builder().withLogEnabled(true).withLogLevel(Log.VERBOSE).withCaptureUncaughtExceptions(true)
        .withContinueSessionMillis(10000).withConsent(new FlurryConsent(true, consentStrings))
            .build(this, flurryAppId);
FlurryAgent.onStartSession(this);

To get the consent strings to add to the builder for GDPR compliance I had to implement the privacy dash project over on github.

Upvotes: 0

Siddharth
Siddharth

Reputation: 9574

I was running FlurryAgent.init(this, "myapikey"); in my on launch Activity and I got a exception on the onStart of my subsequent activity.

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

Upvotes: 0

Srikanth P
Srikanth P

Reputation: 1516

Its Crashes because FlurryAgent is not initialized and you are trying to start the session. So, Initialize FlurryAgent like this:

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 session as shown:

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

@Override

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

Upvotes: 17

ademar111190
ademar111190

Reputation: 14505

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

Upvotes: 5

Related Questions