Calling Super.oncreate() With Null Parameter?
Solution 1:
According to the Android Source code, the Activity.onCreate()
method forwards the saveInstanceState bundle to the activity's fragments. To be more specific, it fetches a parcelable with the "android:fragments" key and forwards this parcelable to the fragments using the FragmentManager.restoreAllStates()
method, which itself restore the state on all fragments.
The Activity.onRestoreInstanceState()
method forwards the bundle to the activity's window. Again it fetches the "android:viewHierarchyState" bundle from the saved instance and forwards it the the window using the Window.restoreHierarchyState()
method.
So to answer your question, if your activity doesn't use Fragments, then indeed calling super.onCreate(null)
won't change anything. But as best practice, I'll advise you to always forward the exact savedInstance bundle (unless you know what you're doing).
Edit : here are the sample source codes I talked about, taken from AOSP v17 :
protectedvoidonCreate(Bundle savedInstanceState) {
// [... some content ellipsed for readability purposes]if (savedInstanceState != null) {
Parcelablep= savedInstanceState.getParcelable(FRAGMENTS_TAG);
mFragments.restoreAllState(p, mLastNonConfigurationInstances != null
? mLastNonConfigurationInstances.fragments : null);
}
mFragments.dispatchCreate();
getApplication().dispatchActivityCreated(this, savedInstanceState);
mCalled = true;
}
// [...]protectedvoidonRestoreInstanceState(Bundle savedInstanceState) {
if (mWindow != null) {
BundlewindowState= savedInstanceState.getBundle(WINDOW_HIERARCHY_TAG);
if (windowState != null) {
mWindow.restoreHierarchyState(windowState);
}
}
}
Solution 2:
The easiest way for you to find this out is by using Log() utility.
Although, bare in mind that you can put stuff into the bundle with
Bundlebdl=newBundle(1);
bdl.putString("file_absolute_path", f.getAbsolutePath());
cf.setArguments(bdl);
And retrieve them with getArguments()
.
So in short - it depends on whether you're using bundle arguments in your app. If no, then it's probably the same.
Post a Comment for "Calling Super.oncreate() With Null Parameter?"