Вопрос

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.. ??

Это было полезно?

Решение

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 method onSaveInstanceState() and later this bundle will be available in onCreate() and in some other methods.

Bundle returned by getArguments() method is the bundle passed from caller of the fragment. This bundle is provided via setArguments() method.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top