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())?
You can make your method to be static:
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 itsonCreate()method, and the Activity will be visible for you.