Skip to content

Commit

Permalink
Make tracker.setLifecycleHandler take a Context instead of an Activity
Browse files Browse the repository at this point in the history
(close #224)
  • Loading branch information
mhadam committed Apr 17, 2018
1 parent 6f54e0e commit b6129e6
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Build;

Expand Down Expand Up @@ -521,14 +522,15 @@ public void pauseSessionChecking() {
/**
* Sets the LifecycleHandler hooks
*
* @param activity The application activity
* @param context The application context
*/
public void setLifecycleHandler(Activity activity) {
public void setLifecycleHandler(Context context) {
if ((this.lifecycleEvents || this.sessionContext) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
LifecycleHandler handler = new LifecycleHandler();
activity.getApplication().registerActivityLifecycleCallbacks(handler);
activity.registerComponentCallbacks(handler);
Application application = (Application)context;
application.registerActivityLifecycleCallbacks(handler);
application.registerComponentCallbacks(handler);
}
}

Expand Down

0 comments on commit b6129e6

Please sign in to comment.