<div dir="ltr">Oh yes, so useless optimization, thanks.</div><br><div class="gmail_quote"><div dir="ltr">Le mar. 14 nov. 2017 à 11:41, Romain Vimont <<a href="mailto:rom@rom1v.com">rom@rom1v.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Le mardi 14 novembre 2017 à 10:37 +0000, Geoffrey Métais a écrit :<br>
> These are 2 different case statements<br>
><br>
> First onCreate()<br>
> Then, onViewCreated() and onActivityCreated()<br>
<br>
With a fall through (no break). So when onCreate() is called,<br>
onViewCreated() and onActivityCreated() are called immediately after.<br>
<br>
> AFAIU.<br>
><br>
> But I don't mind refactoring and set adapter sooner for safety.<br>
><br>
> Le mar. 14 nov. 2017 à 11:15, Romain Vimont <<a href="mailto:rom@rom1v.com" target="_blank">rom@rom1v.com</a>> a écrit :<br>
><br>
> ><br>
> ><br>
> > Le mardi 14 novembre 2017 à 10:04 +0000, Geoffrey Métais a écrit :<br>
> > > onActivityCreated() is still called once the view are inflated, so it<br>
> > can<br>
> > > make a visual difference. That's the idea.<br>
> ><br>
> > The screen may not be refreshed between these two calls, they occur<br>
> > sequentially in the same event in the event loop:<br>
> ><br>
> ><br>
> > <a href="https://github.com/aosp-mirror/platform_frameworks_base/blob/oreo-release/core/java/android/app/FragmentManager.java#L1234" rel="noreferrer" target="_blank">https://github.com/aosp-mirror/platform_frameworks_base/blob/oreo-release/core/java/android/app/FragmentManager.java#L1234</a><br>
> ><br>
> > <a href="https://github.com/aosp-mirror/platform_frameworks_base/blob/oreo-release/core/java/android/app/FragmentManager.java#L1296" rel="noreferrer" target="_blank">https://github.com/aosp-mirror/platform_frameworks_base/blob/oreo-release/core/java/android/app/FragmentManager.java#L1296</a><br>
> ><br>
> > > But yes, creating adapters sooner is definitely safer.<br>
> > ><br>
> > > Le mar. 14 nov. 2017 à 10:56, Romain Vimont <<a href="mailto:rom@rom1v.com" target="_blank">rom@rom1v.com</a>> a écrit :<br>
> > ><br>
> > > ><br>
> > > > Le mardi 14 novembre 2017 à 8:14 +0000, Geoffrey Métais a écrit :<br>
> > > > > The general idea was to offload onCreate(…) in order to have the<br>
> > > > > activities/fragments loaded faster.<br>
> > > ><br>
> > > > All these callbacks are called successively on the UI thread, so<br>
> > > > creating the adapter from one or another may not have any impact on<br>
> > > > "loading faster".<br>
> > > ><br>
> > > > The documentation of onActivityCreated() says:<br>
> > > ><br>
> > > > > It can be used to do final initialization once these pieces are in<br>
> > > > > place, such as retrieving views or restoring state.<br>
> > > ><br>
> > > > In my opinion, adapters should be created in onCreate(), so that they<br>
> > > > may not be null anywhere in your fragment/activity.<br>
> > > ><br>
> > > > What do you think?<br>
> > > ><br>
> > > > > I did not suspect onSaveInstanceState() could be called before<br>
> > > > > onActivityCreated(…)…<br>
> > > > ><br>
> > > > > Le lun. 13 nov. 2017 à 21:00, Romain Vimont <<a href="mailto:rom@rom1v.com" target="_blank">rom@rom1v.com</a>> a écrit<br>
> > :<br>
> > > > ><br>
> > > > > ><br>
> > > > > ><br>
> > > > > > Le lundi 13 novembre 2017 à 18:45 +0100, Geoffrey Métais a écrit :<br>
> > > > > > > vlc-android | branch: 2.5.x | Geoffrey Métais <<br>
> > > > <a href="mailto:geoffrey.metais@gmail.com" target="_blank">geoffrey.metais@gmail.com</a>><br>
> > > > > > | Mon Nov 13 18:40:44 2017 +0100|<br>
> > > > > > [758c200e10ddac5cbad406d4107b431efcdaa2e6] | committer: Geoffrey<br>
> > Métais<br>
> > > > > > ><br>
> > > > > > > Prevent NPE in browsers on device rotation<br>
> > > > > > ><br>
> > > > > > > (cherry picked from commit<br>
> > 45c45adbd5b2b8972fdc28a450333285fa878190)<br>
> > > > > > ><br>
> > > > > > > ><br>
> > > > > ><br>
> > > ><br>
> > <a href="https://code.videolan.org/videolan/vlc-android/commit/758c200e10ddac5cbad406d4107b431efcdaa2e6" rel="noreferrer" target="_blank">https://code.videolan.org/videolan/vlc-android/commit/758c200e10ddac5cbad406d4107b431efcdaa2e6</a><br>
> > > > > > > ---<br>
> > > > > > ><br>
> > > > > > ><br>
> > > > vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java |<br>
> > > > > > 3 ++-<br>
> > > > > > > 1 file changed, 2 insertions(+), 1 deletion(-)<br>
> > > > > > ><br>
> > > > > > > diff --git<br>
> > > > > ><br>
> > a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java<br>
> > > > > ><br>
> > b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java<br>
> > > > > > > index 2a1695b12..5aee19028 100644<br>
> > > > > > > ---<br>
> > > > > ><br>
> > a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java<br>
> > > > > > > +++<br>
> > > > > ><br>
> > b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java<br>
> > > > > > > @@ -245,7 +245,8 @@ public abstract class BaseBrowserFragment<br>
> > extends<br>
> > > > > > SortableFragment<BaseBrowserAd<br>
> > > > > > > public void onSaveInstanceState(Bundle outState){<br>
> > > > > > > outState.putString(KEY_MRL, mMrl);<br>
> > > > > > > outState.putParcelable(KEY_MEDIA, mCurrentMedia);<br>
> > > > > > > - VLCApplication.storeData(KEY_MEDIA_LIST+mMrl,<br>
> > > > > > mAdapter.getAll());<br>
> > > > > > > + if (mAdapter != null)<br>
> > > > > ><br>
> > > > > > Why not just initializing mAdapter in onCreate(…)?<br>
> > > > > ><br>
> > > > > > > + VLCApplication.storeData(KEY_MEDIA_LIST+mMrl,<br>
> > > > > > mAdapter.getAll());<br>
> > > > > > > VLCApplication.storeData(KEY_CONTENT_LIST+mMrl,<br>
> > > > > > mFoldersContentLists);<br>
> > > > > > > if (mRecyclerView != null)<br>
> > > > > > > outState.putInt(KEY_POSITION,<br>
> > > > > > mLayoutManager.findFirstCompletelyVisibleItemPosition());<br>
> > > > > > ><br>
> > > > > > > _______________________________________________<br>
> > > > > > > Android mailing list<br>
> > > > > > > <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> > > > > > > <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
> > > > > > _______________________________________________<br>
> > > > > > Android mailing list<br>
> > > > > > <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> > > > > > <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
> > > > > ><br>
> > > ><br>
> > > > > _______________________________________________<br>
> > > > > Android mailing list<br>
> > > > > <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> > > > > <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
> > > ><br>
> > > > _______________________________________________<br>
> > > > Android mailing list<br>
> > > > <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> > > > <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
> > > ><br>
> ><br>
> > > _______________________________________________<br>
> > > Android mailing list<br>
> > > <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> > > <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
> ><br>
> > _______________________________________________<br>
> > Android mailing list<br>
> > <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> > <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
> ><br>
<br>
> _______________________________________________<br>
> Android mailing list<br>
> <a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
> <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
<br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</blockquote></div>