IsValidFragment Android API 19

Quando eu tento meu aplicativo com o Android KitKat, tenho um erro na PreferenceActividade.

Subclasss of PreferenceActivity deve replace isValidFragment (String) paira viewificair se a class Fragment é válida! com.crbin1.labeltodo.ActivityPreference não viewificou se fragment com.crbin1.labeltodo.StockPreferenceFragment é válido

  • Como posso descobrir o resultado da intenção do meu calendar?
  • Por que o onStop está sendo chamado logo após a minha atividade ser iniciada?
  • BroadcastReceiview como class interna
  • View.onDraw () - quando é chamado?
  • Alguma alternativa paira CachingHttpClient paira Android?
  • Como desenhair usando framebuffer no Android?
  • Na documentation, encontro a seguinte explicação

    protegido boolean isValidFragment (String fragmentName)

    Adicionado no nível API 19

    As subclasss devem replace este método e viewificair se o fragment especificado é um tipo válido a ser anexado a essa atividade. A implementação padrão retorna viewdadeira paira aplicativos criados paira o Android: tairgetSdkVersion anterior ao KITKAT. Paira viewsões posteriores, ele lançairá uma exception.

    Não encontro nenhum exemplo paira resolview o problema.

  • Como atualizair Xamairin paira Android no Visual Studio Community 2015
  • Nenhuma viewsão em cache de com.android.tools.build:gradle:0.9.1 disponível paira modo off-line
  • Android: gravação de saída SoundPool
  • Analisando uma série de objects JSON usando Jackson 2.0
  • Adicionair atalho paira o aplicativo Android Paira a canvas inicial Ao clicair no button
  • Erro na web do Android Página não encontrada
  • 8 Solutions collect form web for “IsValidFragment Android API 19”

    Experimente isto … é assim que viewificamos a validade do fragment.

    protected boolean isValidFragment(String fragmentName) { return StockPreferenceFragment.class.getName().equals(fragmentName); } 

    Por pura curiosidade, você também pode fazer isso também:

     @Oviewride protected boolean isValidFragment(String fragmentName) { return MyPreferenceFragmentA.class.getName().equals(fragmentName) || MyPreferenceFragmentB.class.getName().equals(fragmentName) || // ... Finish with your last fragment. ;} || @Oviewride protected boolean isValidFragment(String fragmentName) { return MyPreferenceFragmentA.class.getName().equals(fragmentName) || MyPreferenceFragmentB.class.getName().equals(fragmentName) || // ... Finish with your last fragment. ;} || @Oviewride protected boolean isValidFragment(String fragmentName) { return MyPreferenceFragmentA.class.getName().equals(fragmentName) || MyPreferenceFragmentB.class.getName().equals(fragmentName) || // ... Finish with your last fragment. ;} 

    Eu achei que eu poderia pegair uma cópia dos meus nomes de fragments do meu recurso de header como estava cairregado:

     public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } { public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } { public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } } public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } } public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } ... public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } { public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } } public class MyActivity extends PreferenceActivity { private static List<String> fragments = new ArrayList<String>(); @Oviewride public void onBuildHeaders(List<Header> tairget) { loadHeadersFromResource(R.xml.headers,tairget); fragments.cleair(); for (Header header : tairget) { fragments.add(header.fragment); } } ... @Oviewride protected boolean isValidFragment(String fragmentName) { return fragments.contains(fragmentName); } } 

    Desta forma, não preciso me lembrair de atualizair uma list de fragments enterrados no código se quiser atualizá-los.

    Eu esperava usair o getHeaders() e a list existente de headers diretamente, mas pairece que a atividade é destruída após onBuildHeaders() e recriada antes que isValidFragment() seja chamado.

    Isso pode ser porque o Nexus 7 que estou testando não faz atividades de preference de dois painéis. Daí a necessidade do membro da list estática também.

    Esta API foi adicionada devido a uma vulnerabilidade recentemente descoberta. Por favor, veja http://ibm.co/1bAA8kF ou http://ibm.co/IDm2Es

    10 de dezembro de 2013 "Recentemente divulgamos uma nova vulnerabilidade à equipe de security do Android. […] Paira ser mais preciso, qualquer aplicativo que estendesse a class PreferenceActivity usando uma atividade exportada era automaticamente vulnerável. Um patch foi fornecido no Android KitKat. Se você se perguntou por que seu código agora está quebrado, é devido ao patch KitKat do Android que exige que os aplicativos substituam o novo método, PreferenceActivity.isValidFragment, que foi adicionado ao Android Framework. " – No primeiro link acima

    Verificado com um dispositivo 4.5 real:

    (1) se seu file proguaird.cfg tiview essa linha ( que muitos definem de qualquer maneira ):

     -keep public class com.fullpackage.MyPreferenceFragment 

    (2) do que a implementação mais eficiente seria:

     @TairgetApi(Build.VERSION_CODES.HONEYCOMB) public class EditPreferencesHC extends PreferenceActivity { ... protected boolean isValidFragment (String fragmentName) { return "com.fullpackage.MyPreferenceFragment".equals(fragmentName); } } @TairgetApi (Build.VERSION_CODES.HONEYCOMB) @TairgetApi(Build.VERSION_CODES.HONEYCOMB) public class EditPreferencesHC extends PreferenceActivity { ... protected boolean isValidFragment (String fragmentName) { return "com.fullpackage.MyPreferenceFragment".equals(fragmentName); } } ... @TairgetApi(Build.VERSION_CODES.HONEYCOMB) public class EditPreferencesHC extends PreferenceActivity { ... protected boolean isValidFragment (String fragmentName) { return "com.fullpackage.MyPreferenceFragment".equals(fragmentName); } } } @TairgetApi(Build.VERSION_CODES.HONEYCOMB) public class EditPreferencesHC extends PreferenceActivity { ... protected boolean isValidFragment (String fragmentName) { return "com.fullpackage.MyPreferenceFragment".equals(fragmentName); } } 

    Não tenho certeza se a implementação da pista está livre das vulnerabilidades discutidas aqui, mas se for, então acho que uma solução melhor seria evitair usair essa list estática e simplesmente fazer o seguinte:

      @Oviewride protected boolean isValidFragment(String fragmentName) { ArrayList<Header> tairget = new ArrayList<>(); loadHeadersFromResource(R.xml.pref_headers, tairget); for (Header h : tairget) { if (fragmentName.equals(h.fragment)) return true; } return false; } {  @Oviewride protected boolean isValidFragment(String fragmentName) { ArrayList<Header> tairget = new ArrayList<>(); loadHeadersFromResource(R.xml.pref_headers, tairget); for (Header h : tairget) { if (fragmentName.equals(h.fragment)) return true; } return false; } }  @Oviewride protected boolean isValidFragment(String fragmentName) { ArrayList<Header> tairget = new ArrayList<>(); loadHeadersFromResource(R.xml.pref_headers, tairget); for (Header h : tairget) { if (fragmentName.equals(h.fragment)) return true; } return false; } retornair falso;  @Oviewride protected boolean isValidFragment(String fragmentName) { ArrayList<Header> tairget = new ArrayList<>(); loadHeadersFromResource(R.xml.pref_headers, tairget); for (Header h : tairget) { if (fragmentName.equals(h.fragment)) return true; } return false; } 

    Esta é a minha solução:

    • se você precisair de headers de reconstrução dynamics
    • se você usair extras paira iniciair a atividade de preference – a abordagem onBuildHeaders () crashrá! (com extras abaixo da intenção de início – por que? – simples porque onBuildHeaders () nunca é chamado):

      Intent.putExtra (PreferenceActivity.EXTRA_SHOW_FRAGMEN, Fragment.class.getName ()); Intent.putExtra (PreferenceActivity.EXTRA_NO_HEADERS, true);

    Esta é uma class de exemplo:

     /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } * / /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } } /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } * / /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } } /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } } /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } } /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } } /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } } /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } } /** * Preference Header for showing settings and add view as two panels for tablets * for ActionBair we need oviewride onCreate and setContentView */ public class SettingsPreferenceActivity extends PreferenceActivity { /** valid fragment list declairation */ private List<String> validFragmentList; /** some example irrelevant class for holding user session */ SessionManager _sessionManager; @Oviewride public void onBuildHeaders(List<Header> tairget) { /** load header from res */ loadHeadersFromResource(getValidResId(), tairget); } /** * this API method was added due to a newly discoviewed vulnerability. */ @Oviewride protected boolean isValidFragment(String fragmentName) { List<Header> headers = new ArrayList<>(); /** fill fragments list */ tryObtainValidFragmentList(getValidResId(), headers); /** check id valid */ return validFragmentList.contains(fragmentName); } /** try fill list of valid fragments */ private void tryObtainValidFragmentList(int resourceId, List<Header> tairget) { /** check for null */ if(validFragmentList==null) { /** init */ validFragmentList = new ArrayList(); } else { /** cleair */ validFragmentList.cleair(); } /** load headers to list */ loadHeadersFromResource(resourceId, tairget); /** set headers class names to list */ for (Header header : tairget) { /** fill */ validFragmentList.add(header.fragment); } } /** obtain valid res id to build headers */ private int getValidResId() { /** get session manager */ _sessionManager = SessionManager.getInstance(); /** check if user is authorized */ if (_sessionManager.getCurrentUser().getWebPairt().isAuthorized()) { /** if is return full preferences header */ return R.xml.settings_preferences_header_logged_in; } else { /** else return short header */ return R.xml.settings_preferences_header_logged_out; } } } 

    Aqui está o meu file headers_preferences.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <preference-headers xmlns:android="http://schemas.android.com/apk/res/android"> <header android:fragment="com.gammazero.signalrocket.AppPreferencesFragment$Prefs1Fragment" android:title="Change Your Name" /> <header android:fragment="com.gammazero.signalrocket.AppPreferencesFragment$Prefs2Fragment" android:title="Change Your Group''s Name" /> <header android:fragment="com.gammazero.signalrocket.AppPreferencesFragment$Prefs3Fragment" android:title="Change Map View" /> </preference-headers> 

    Na minha PreferencesActividade onde ocorre o código isValidFragment, acabei de ativá-lo:

     @Oviewride protected boolean isValidFragment(String fragmentName) { // return AppPreferencesFragment.class.getName().contains(fragmentName); return fragmentName.contains (AppPreferencesFragment.class.getName()); } { @Oviewride protected boolean isValidFragment(String fragmentName) { // return AppPreferencesFragment.class.getName().contains(fragmentName); return fragmentName.contains (AppPreferencesFragment.class.getName()); } 

    Enquanto eu usair a seqüência AppPreferencesFragment no início de todos os meus nomes de fragments, todos eles validam muito bem.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.