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