Search code examples
androidflurry

Can i put flurry code in onCreate() and onDestroy()?


I am trying to use flurry for my android app. It says that i should put flurry code in onStart() and onStop() methods. I dont have these methods in my code. I have two activities and both use onCreate() and onDestroy() methods only. Can i put flurry code in that? Will there be any problem with it?


Solution

  • onStart() and onStop() are methods that handle part of an activity lifecycle, so you can add them to your activities without any problem.

    @Override
    protected void onCreate(...) {
        super.onCreate(...);
                ...
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        FlurryAgent.onStartSession(this, "your_key");
    }
    
    @Override
    public void onStop()
    {
       super.onStop();
       FlurryAgent.onEndSession(this);
    }