0

I have a Preference tag inside PreferenceScreen called "faq" and I want to open another Activity when tapping on it. What is the right way to do that? There is a similar question on this link: Android: Start Activity from preferences.xml Is there any other way so I can handle some sort of action when tap on this item ?

<PreferenceScreen
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <SwitchPreferenceCompat
        app:key="notifications"`enter code here`
        app:title="Enable message notifications"/>
    <Preference
        app:key="faq"
        app:title="FAQ" />
</PreferenceScreen>
Ali Roshanbin
  • 175
  • 1
  • 15

1 Answers1

0

One way that you can write your code based on the Preference key that has been selected would be this code in the SettingsActivity : Any other appropriate way will be appreciated.

@Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        String key = preference.getKey();
        if (key.equals(getString(R.string.faq_key))) {
            Intent intent = new Intent(this, FAQActivity.class);
            startActivity(intent);
            return true;
        } else if (key.equals(getString(R.string.privacy_policy_key))) {
            // do something
            return true;
        } else if (key.equals(getString(R.string.terms_of_service_key))) {
            // do something
            return true;
        }
        return false;
    }
Ali Roshanbin
  • 175
  • 1
  • 15