0

I am trying to launch a activity from my preference screen, any help would be greatly appreciated. Here is some code i have been playing around with.

  Preference customerPref2 = (Preference) findPreference("community");
  customerPref2.setOnPreferenceClickListener(new  OnPreferenceClickListener() {

   public boolean onPreferenceClick(Preference preference) {
              Toast.makeText(getBaseContext(),
                "Launching Activity", 
              Toast.LENGTH_SHORT).show();
          Intent intent = new Intent();                                                                 
          intent.setClassName("com.xxx.xxxx", "Community" );
          intent.setClass(Prefs.this, Community.class);
          startActivity(intent);

I dont know what part of this code to use, so i included both the setClassName and just the setClass

Preference.xml

     <Preference
            android:title="Checkout this Activity"
            android:summary="Launch the Activity"
            android:key="community">

     <intent android:action="android.intent.action.VIEW"
         android:targetPackage="com.xxx.xxxx"
         android:targetClass="com.xxx.xxxx.Community

Also what i have found is people saying to enusre your manifest is right, due to when i am trying to launch the activity sometime says its not able to find it. here is my manifest

   <activity android:name=".Community" android:label="@string/gotodashboard">
        <intent-filter>
            <action android:name="android.intent.category.VIEW" />
            <category android:name="android.intent.category.PREFERENCE" />
        </intent-filter>
    </activity> 

Any help or source code examples will help me figure this out. Thanks gusy.

Jaison Brooks
  • 5,816
  • 7
  • 43
  • 79

1 Answers1

1

I have resolved the Question by chaging the code in my prefs java file to this.

 public boolean onPreferenceClick(Preference preference) {
     Intent myIntent = new Intent(Prefs.this, Community.class);
     Prefs.this.startActivity(myIntent);
     return true;
   }
Jaison Brooks
  • 5,816
  • 7
  • 43
  • 79