简体   繁体   中英

Android Studio Settings Activity doesn't work

As far as I can understand from the documentation the settings activity which comes as a template with Android Studio should work. However, it doesn't seem to launch anything on my phone.

I understand that it's meant to work for both tablets and phones. I'm running Android 5.0 and I have successfully used it as a test device before. I have yet to test it on a tablet.

Well, I'm using the default template that's supplied with android studio for the settings activity. I didn't post it since it extends across several pages (5 xml files and 1 class file).

http://www.pastebin.com/kehbMSqg -SettingsActivity.class. (That's the class which I set to launch.)

http://pastebin.com/GHjZRn68 -pref_data_sync.xml

http://pastebin.com/0FaaH8zR -pref_general.xml

http://pastebin.com/yixMwAaJ -pref_headers.xml

http://pastebin.com/46W1dREG -pref_notification.xml

Any help would be useful Thanks!

This may be related to a fix for a fragment injection vulnerability that was patched in KITKAT. If you are running the app for a targetSdkVersion since KITKAT, an exception will be thrown when the SettingsActivity tries to launch a PreferenceFragment.

You need to override the PreferenceActivity.isValidFragment() method. For the Settings Activity template in Android Studio 1.3.2 you can use:

@Override
protected boolean isValidFragment(String fragmentName) {
    return fragmentName.equals(GeneralPreferenceFragment.class.getName())
            || fragmentName.equals(NotificationPreferenceFragment.class.getName())
            || fragmentName.equals(DataSyncPreferenceFragment.class.getName());
}

Related stackoverflow post: isValidFragment Android API 19

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM