Move initialization of SearchView from onAttach to onActivityCreated
Having the initialization code in onAttach causes the app to crash
whenever the fragment/activity has to be recreated for whatever reason.
onActivityCreated is also the logically correct home for this code as
activity creating is the prerequisite for the SearchView to be
initialized.
package org.edx.mobile.view;
-import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
@@ -42,11 +41,10 @@ public class WebViewDiscoverCoursesFragment extends BaseWebViewDiscoverFragment
}
@Override
- public void onAttach(Context context) {
- super.onAttach(context);
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
toolbarCallbacks = (MainDashboardToolbarCallbacks) getActivity();
initSearchView();
-
}
private void initSearchView() {
