安卓&捆绑包
myBundle 和 myBundle 之间有什么区别? getArguments() 返回的对象
@Override
public void onCreate(Bundle myBundle) { //on create() belonging to a Fragment
super.onCreate(myBundle);
// So myBundle vs getArguments()
}
从我的简单测试来看,它们不是同一个对象,测试如下:
private void compareThem(Bundle myBundle, Bundle arguments) {
Log.d("---myBundle==null: ", " " + (myBundle==null));
Log.d("---arguments==null: ", " " + (arguments==null));
if(myBundle!=null && arguments!=null) {
Log.d("---myBundle==arguments: ", " " + (myBundle==arguments));
Log.d("---myBundle.equals(arguments): ", " " + (myBundle.equals(arguments)));
}
}
有时我收到: false, true, false, false 有时: false, false, false, false 不管怎样..??
what is the difference between: myBundle & the one returned by getArguments()
@Override
public void onCreate(Bundle myBundle) { //on create() belonging to a Fragment
super.onCreate(myBundle);
// So myBundle vs getArguments()
}
From my simple test they are not the same object, tested this with:
private void compareThem(Bundle myBundle, Bundle arguments) {
Log.d("---myBundle==null: ", " " + (myBundle==null));
Log.d("---arguments==null: ", " " + (arguments==null));
if(myBundle!=null && arguments!=null) {
Log.d("---myBundle==arguments: ", " " + (myBundle==arguments));
Log.d("---myBundle.equals(arguments): ", " " + (myBundle.equals(arguments)));
}
}
Sometimes I receive: false, true, false, false sometimes: false, false, false, false
Anyways.. ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
onCreate()
中传递的 Bundle(代码中的 myBundle)被称为 savingInstanceState。您可以在方法onSaveInstanceState()
以及稍后此捆绑包将在onCreate()
和其他一些方法中可用。getArguments()
返回的捆绑包 方法是从片段的调用者传递的包。该捆绑包是通过 setArguments() 方法提供的。Bundle passed in
onCreate()
(myBundle in your code) is so called savedInstanceState. You can save some data ("state") from the fragment in the bundle in the methodonSaveInstanceState()
and later this bundle will be available inonCreate()
and in some other methods.Bundle returned by
getArguments()
method is the bundle passed from caller of the fragment. This bundle is provided viasetArguments()
method.