android构造函数,Android片段:真的需要空构造函数吗?

is empty constructor really required?

是.

Why does it work when orientation does not change?

因为Android不会尝试重新创建您的片段.

Why does it fail when orientation is changed?

因为Android正在重新创建你的片段.

当配置发生更改(例如,方向更改)时,默认情况下,Android会破坏并重新创建您的活动,并且还会破坏并重新创建该活动中的片段. “重新创建片段”部分是您需要片段上的零参数公共构造函数的原因.它也用于其他情况,例如FragmentStatePagerAdapter.

All subclasses of Fragment must include a public empty constructor. The framework will often re-instantiate a fragment class when needed,in particular during state restore,and needs to be able to find this constructor to instantiate it. If the empty constructor is not available,a runtime exception will occur in some cases during state restore.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值