setHasOptionsMenu() should be called from fragment's onCreate()

This commit is contained in:
tonymanou 2017-01-11 22:22:55 +01:00 committed by topjohnwu
parent e1aabd70e8
commit e9f04256c9
3 changed files with 20 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.view.LayoutInflater;
@ -50,6 +51,13 @@ public class LogFragment extends Fragment {
private MenuItem mClickedMenuItem;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.log_fragment, container, false);
@ -65,7 +73,6 @@ public class LogFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
setHasOptionsMenu(true);
new LogManager().read();
getActivity().setTitle(R.string.log);
}

View File

@ -46,6 +46,12 @@ public class MagiskHideFragment extends Fragment implements CallbackHandler.Even
private SearchView.OnQueryTextListener searchListener;
private String lastFilter;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -89,7 +95,6 @@ public class MagiskHideFragment extends Fragment implements CallbackHandler.Even
@Override
public void onResume() {
super.onResume();
setHasOptionsMenu(true);
getActivity().setTitle(R.string.magiskhide);
CallbackHandler.register(packageLoadDone, this);
if (packageLoadDone.isTriggered) {

View File

@ -47,8 +47,13 @@ public class ReposFragment extends Fragment implements CallbackHandler.EventList
private SearchView.OnQueryTextListener searchListener;
@Nullable
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.repos_fragment, container, false);
@ -106,7 +111,6 @@ public class ReposFragment extends Fragment implements CallbackHandler.EventList
@Override
public void onResume() {
super.onResume();
setHasOptionsMenu(true);
CallbackHandler.register(repoLoadDone, this);
getActivity().setTitle(R.string.downloads);
}