Why does Kit Kat require the use of the isValidFragment?

前端 未结 4 2512
北恋
北恋 2021-02-20 11:09

Ever since KitKat was released, I\'ve noticed a whole bunch of my apps updating with \"Fixing a crash in Kit Kat\". Recently when I released my own app, I figured out the likely

4条回答
  •  走了就别回头了
    2021-02-20 11:51

    Taken from a blog of commonsware.

    Once you target API Level 19 or higher, you will need to override isValidFragment() in your PreferenceActivity, to validate that the supplied fragment class name is indeed something that should be displayed. Off the cuff, this feels like some hack to deal with a security flaw.

    Documentation says

    protected boolean isValidFragment (String fragmentName)

    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.

提交回复
热议问题