title: requireActivity().getApplicationContext() "may produce a NullPointerExeption"
body: <p>Bellow there is some of the code of my application. The part where I need help is in <code>requireActivity()</code> in SettingFragment.java:</p>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>...
  public class MainActivity extends AppCompatActivity {
     
     @Override
     protected void onCreate(Bundle savedInstanceState) {
        ...
     }
  
     public void iniciarIntent3() {   //this method is called by a button in activity_main.xml
          Intent intent = new Intent(this, Settings.class);
          startActivityForResult(intent, 1);
     }
  }
  </code></pre>
  <p><strong>Settings.java</strong></p>
  <pre><code>...
  
  public class Settings extends AppCompatActivity implements SettingsFragment.SendToActivity {
     ...
     @Override
     protected void onCreate(Bundle savedInstanceState) {
        ...
        if (savedInstanceState == null) {
           getSupportFragmentManager()
              .beginTransaction()
              .replace(R.id.settings, new SettingsFragment())
              .commit();
        }
     }
  
     @Override
     public void onAttachFragment(Fragment fragment) {
        if (fragment instanceof SettingsFragment) {
           SettingsFragment settingsFragment = (SettingsFragment) fragment;
           settingsFragment.setSendToActivity(this);
        }
     }
     public void send(int result) {
        ...
     }
  }   
  </code></pre>
  <p><strong>SettingsFragment.java</strong></p>
  <pre><code>public class SettingsFragment extends PreferenceFragmentCompat {
  
     SendToActivity callback;
  
     public void setSendToActivity (SendToActivity callback) {
        this.callback = callback;
     }
  
     public interface SendToActivity {
        void send(int result);
     }
     
     if (editTextPreference != null) {
        editTextPreference.setOnBindEditTextListener(new 
        EditTextPreference.OnBindEditTextListener() {
           @Override
           public void onBindEditText(@NonNull EditText editText) {
              editText.setInputType(InputType.TYPE_CLASS_NUMBER);
              editText.setText(&quot;&quot;);                
              editText.setBackground(ContextCompat.getDrawable(requireActivity()
                 .getApplicationContext(), R.drawable.fondo_edittextpreference));
           }
        });
     }
     ...
  }
  </code></pre>
  <p>I just want to be sure that <code>requireActivity()</code> in SettingsFragment class is not going to throw a nullpointerexeption. Can you help me to check?</p>