Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why com.facebook.Settings.publishInstallAsync in onResume?

I looked into the Facebook SDK 3.0 to try and find out how to track installs coming from a Facebook campaign and saw this in the documentation:

For the FB Android SDK 3.0, add the following to onResume() of each Activity in your app: com.facebook.Settings.publishInstallAsync(context, YOUR_APP_ID);

I have 2 basic questions:

  1. Why is this happening in every activity instead of in the launcher activity?

  2. Why is this happening in the onResume method instead of onStart? Android recommends not doing things like this in the onResume.

Edit - even though it's asynchronous doing this over and over seems stupid and un necessary

like image 430
thepoosh Avatar asked Jun 09 '13 07:06

thepoosh


1 Answers

The answer to both questions is that by including the call in the onResume() method of every Activity you're dealing with network failures at the time the user first starts the app. In other words, your app will try to publish the installation every time an Activity is shown in the foreground, not just when the first Activity is started.

From Facebook Developers Mobile App Install Ads:

This will allow the app to ping back the install event to Facebook when the user opens up the app for the first time, and again in the future if there is a network error. Our client code will stop sending installs once it acquires a success code from the server, and our back-end will only count the install a single time if it receives multiple hits for the same device

like image 146
arlanthir Avatar answered Nov 10 '22 06:11

arlanthir