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?

Answers


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

onStart and onStop are existing methods on an Activity, just like onCreate. If you want to add functionality at these points of the activity lifecycle, you can override them just like you did for onCreate.

public class MyActivity extends Activity {
    @Override
    protected void onStart() {
        super.onStart();
        FlurryAgent.onStartSession(this, "FLURRYKEY");
    }

    @Override
    public void onStop()
    {
       FlurryAgent.onEndSession(this);
       super.onStop();
    }
}

onCreate and onDestroy are not an appropriate pair of methods to use for Flurry session tracking because onDestroy is not guaranteed to be called. See the documention on onDestroy. You can end up with situations where the app gets killed by the system and Flurry will think the session is still going.

There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away.


Need Your Help

Deploying rails 4 app on cpanel hostgator ssh

ruby-on-rails deployment ssh cpanel

I am using Ubuntu and I am getting stuck connecting to remote hostgator server. I am using ssh command terminal instead of the recommended puTTY for windows. I ran ssh ssh username@hostname but got...

groovy error MissingPropertyException: No such property

java groovy

I am doing a groovy tutorial and I used the code from the book 'Programming Groovy'.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.