diff --git a/collect_app/src/main/java/org/odk/collect/android/preferences/FormMetadataFragment.java b/collect_app/src/main/java/org/odk/collect/android/preferences/FormMetadataFragment.java index 7410e864b81..c34cd63a625 100644 --- a/collect_app/src/main/java/org/odk/collect/android/preferences/FormMetadataFragment.java +++ b/collect_app/src/main/java/org/odk/collect/android/preferences/FormMetadataFragment.java @@ -1,6 +1,6 @@ package org.odk.collect.android.preferences; -import android.app.Activity; +import android.content.Context; import android.os.Bundle; import androidx.fragment.app.FragmentActivity; @@ -35,9 +35,9 @@ public class FormMetadataFragment extends PreferenceFragmentCompat { PermissionUtils permissionUtils; @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - DaggerUtils.getComponent(activity).inject(this); + public void onAttach(Context context) { + super.onAttach(context); + DaggerUtils.getComponent(context).inject(this); } @Override @@ -55,7 +55,9 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initNormalPrefs(); - if (savedInstanceState == null) { + if (permissionUtils.isReadPhoneStatePermissionGranted(getActivity())) { + initDangerousPrefs(); + } else if (savedInstanceState == null) { permissionUtils.requestReadPhoneStatePermission(getActivity(), true, new PermissionListener() { @Override public void granted() { @@ -66,8 +68,6 @@ public void granted() { public void denied() { } }); - } else if (permissionUtils.isReadPhoneStatePermissionGranted(getActivity())) { - initDangerousPrefs(); } } diff --git a/docs/CODE-GUIDELINES.md b/docs/CODE-GUIDELINES.md index 73c13130766..f907b281ebd 100644 --- a/docs/CODE-GUIDELINES.md +++ b/docs/CODE-GUIDELINES.md @@ -118,9 +118,9 @@ For Fragment objects you should hook into the `onAttach` lifecycle method instea ```java @Override -public void onAttach(Activity activity) { - super.onAttach(activity); - DaggerUtils.getComponent(activity).inject(this); +public void onAttach(Context context) { + super.onAttach(context); + DaggerUtils.getComponent(context).inject(this); } ```