码迷,mamicode.com
首页 > 其他好文 > 详细

继承PreferenceActivity 需要验证Frag是否有效

时间:2016-10-19 17:14:00      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

错误如下:

Caused by: java.lang.RuntimeException: Subclasses of PreferenceActivity must override isValidFragment(String) to verify that the Fragment class is valid! com.example.silence.otherapp.PreferenceActivityTest has not checked if fragment com.example.silence.otherapp.PreferenceActivityTest$Prefs1Fragment is valid.

 

原因:SDK19以上的安全限制,需要重写isValidFragment

 

protected boolean isValidFragment (String fragmentName)

Added in API level 19

Subclasses should override this method and verify that the given fragment is a 
valid type to be attached to this activity. The default implementation returns 
true for apps built for Android:targetSdkVersion older than KITKAT. For later 
versions, it will throw an exception.

 

解决方法:

@Override
protected boolean isValidFragment (String fragmentName) {
  return [YOUR_FRAGMENT_NAME].class.getName().equals(fragmentName);
}

或者

@Override
protected boolean isValidFragment (String fragmentName) {
  return true;
}

继承PreferenceActivity 需要验证Frag是否有效

标签:

原文地址:http://www.cnblogs.com/xfz329/p/5977562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!