Get an Activity from Custom Settings

I am trying to integrate facebook-connect into my android app. All the examples that I see over the Internet create a connection with Android activity. I am doing something completely different, the user can configure his connection to facebook using user settings. I was successful when I did this for twitter and foursquare. However, the Facebook.authorize method requires an Activity as parameter, and since I'm in preference, I cannot find a link to the activity object.

So my question is how to get a link to activity inside a preference?

Thanks to everyone T

+4
source share
3 answers

I managed to get the Activity link by hovering the Context object in the Activity.

Activity activity = (Activity) context; 

or with custom activity, you can also do this

 SettingsActivity activity = (SettingsActivity) context; 
+6
source

This is an old question, although I use the following function with a preference fragment com.android.support:preference :

 public static Activity getPrefActivity(Preference pref) { Context c = pref.getContext(); if (c instanceof ContextThemeWrapper) { if (((ContextThemeWrapper) c).getBaseContext() instanceof Activity) return (Activity) ((ContextThemeWrapper) c).getBaseContext(); } else if (c instanceof Activity) return (Activity) c; return null; } 
+1
source

Assuming you have an action called MyActivity , can you just use MyActivity.class ?

0
source

All Articles