0

Is it possible to start a method of a specific class from a preference instead of creating the object of the class?

<PreferenceCategory
    android:key="facebook_cat"
    android:title="Σύνδεση με Facebook" >
    <PreferenceScreen
        android:key="facebook_screen"
        android:summary="Δεν έχετε συνδεθεί στο Facebook. Πατήστε κλικ εδώ για να συνδεθήτε."
        android:title="Αποσυνδεδεμένος" >
        <intent
         -->android:targetClass="com.testproject.facebook.FacebookConnectActivity" <--
            android:targetPackage="com.testproject" />
    </PreferenceScreen>
</PreferenceCategory>

facebookConnectActivity is a class. Inside that class I have created a public void called log().

Is it possible to start that instead of creating a whole object of FacebookActivity (hence starting the log() instead of onCreate())?

Akshay
  • 2,506
  • 4
  • 34
  • 55
Alex Styl
  • 3,982
  • 2
  • 28
  • 47

1 Answers1

1

You can make your method to be static:

public static void log()

And to call it from your Preference, just: FacebookConnectActivity.log();

And to be clear, you don't create objects that extends Activity, because there is no constructor there, you should call: startActivity() in order to call its onCreate() method, and the Activity will be visible for you.

Carnal
  • 21,744
  • 6
  • 60
  • 75
  • i tried writing android:targetClass="com.testproject.facebook.FacebookConnectActivity.log()" but it said there weren't such classes with that name on the adroid manifest file... Since I got around a different approach, and since I got no more answers, i'll just upvote you and mark as answer. Thanks for the reply :) – Alex Styl Aug 31 '12 at 10:25