Get Activity from Service (Daydream)

618 Views Asked by At

I'm trying to make a daydream that uses the Facebook SDK with Android-Simple-Facebook.

Daydreams run as a service and has no associated activity as far as I am aware. I'm having an issue where I need to pass an Activity (not a context...) through to Android-Simple-Facebook, which passes it to the Facebook SDK. I drilled through some of the methods and found this one to to be the issue:

public UiLifecycleHelper(android.app.Activity activity
    com.facebook.Session.StatusCallback callback) { /* compiled code */ }

I am not sure how I can use this anymore if I don't have an activity. I can understand using this to help with the "lifecycle" but it seems like a terrible decision to use Activity instead of Context.

The code that doesn't work in mine is:

mSimpleFacebook = SimpleFacebook.getInstance(this); //this needs to be activity, 
    not DreamService, which extends Context

I tried

Activity activity = new Activity();
mSimpleFacebook = SimpleFacebook.getInstance(activity);

but further down the line its trying to get a context which it can't.

java.lang.NullPointerException: Attempt to invoke virtual method 
'android.content.Context android.content.Context.getApplicationContext()' 
on a null object reference

Anyone have any ideas? This is going to be a serious dealbreaker if I can't get it to work.

0

There are 0 best solutions below