-
-
Save billmote/43b7a2a3058f058f6144 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.app.Application; | |
import android.os.Bundle; | |
import com.google.analytics.tracking.android.EasyTracker; | |
public class MainApplication extends Application { | |
int visibleActivities = 0; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
appBackgroundedDetector(); | |
} | |
private void appBackgroundedDetector() { | |
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { | |
@Override | |
public void onActivityCreated(Activity activity, Bundle bundle) { | |
} | |
@Override | |
public void onActivityStarted(Activity activity) { | |
EasyTracker.getInstance(MainApplication.this).activityStart(activity); | |
} | |
@Override | |
public void onActivityResumed(Activity activity) { | |
visibleActivities++; | |
if (visibleActivities > 0) { | |
// updateLocation after "so long" | |
} | |
} | |
@Override | |
public void onActivityPaused(Activity activity) { | |
visibleActivities--; | |
} | |
@Override | |
public void onActivityStopped(Activity activity) { | |
EasyTracker.getInstance(MainApplication.this).activityStop(activity); | |
} | |
@Override | |
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { | |
} | |
@Override | |
public void onActivityDestroyed(Activity activity) { | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment