Do fragments really need an empty constructor?

后端 未结 4 1605
星月不相逢
星月不相逢 2020-11-22 07:12

I have a Fragment with a constructor that takes multiple arguments. My app worked fine during development, but in production my users sometimes see this crash:<

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 07:42

    As noted by CommonsWare in this question https://stackoverflow.com/a/16064418/1319061, this error can also occur if you are creating an anonymous subclass of a Fragment, since anonymous classes cannot have constructors.

    Don't make anonymous subclasses of Fragment :-)

提交回复
热议问题