title: Wanting to use a static method in a non static method from different classes
body: <p>I am very new to Java and making Android projects but I want to basically turn on &quot;do not disturb&quot; at a specific time. I have tried making sub class and making all the things static/non static. Nothing seems to be working. I need two extends which I cannot use in the same class. Is there a solution/better way to do this? If I'm not mistaken Receivers need to be static while the myactivity class cannot be.</p>
  <p>Class MainActivity.java This is where the DND function is</p>
  <pre><code>package com.example.myapplication;
  
  import android.app.Activity;
  import android.app.AlarmManager;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Build;
  import android.os.Bundle;
  import android.provider.Settings;
  import android.view.View;
  import android.widget.LinearLayout;
  import android.widget.TimePicker;
  import android.widget.Toast;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import java.util.Calendar;
  
  public class MainActivity extends AppCompatActivity {
      private static NotificationManager mNotificationManager;
      private Context mContext;
      private Activity mActivity;
  
      TimePicker timePicker;
  
      private AlarmManager alarmMgr;
      private PendingIntent alarmIntent;
      private BroadcastReceiver mReceiver;
      public LinearLayout mRootLayout;
      static Intent intent;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          //getting the timepicker object
          timePicker = (TimePicker) findViewById(R.id.timePicker);
  
          //attaching clicklistener on button
          findViewById(R.id.buttonAlarm).setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  //We need a calendar object to get the specified time in millis
                  //as the alarm manager method takes time in millis to setup the alarm
                  Calendar calendar = Calendar.getInstance();
                  if (android.os.Build.VERSION.SDK_INT &gt;= 23) {
                      calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
                              timePicker.getHour(), timePicker.getMinute(), 0);
                  } else {
                      calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
                              timePicker.getCurrentHour(), timePicker.getCurrentMinute(), 0);
                  }
  
  
                  setAlarm(calendar.getTimeInMillis());
              }
          });
      }
  
      private void setAlarm(long time) {
          //getting the alarm manager
          AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  
          //creating a new intent specifying the broadcast receiver
          Intent i = new Intent(this, MyAlarm.class);
  
          //creating a pending intent using the intent
          PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
  
          //setting the repeating alarm that will be fired every day
          am.setRepeating(AlarmManager.RTC, time, AlarmManager.INTERVAL_DAY, pi);
          Toast.makeText(this, &quot;Alarm is set&quot;, Toast.LENGTH_SHORT).show();
      }
  
      public static void changeInterruptionFilter(int interruptionFilter) {
  
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) { // If api level minimum 23
              mNotificationManager.setInterruptionFilter(interruptionFilter);
              // If notification policy access granted for this package
              if (mNotificationManager.isNotificationPolicyAccessGranted()) {
  
                  mNotificationManager.setInterruptionFilter(interruptionFilter);
                  // Set the interruption filter
  
              } else {
  
  
                  intent = new Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
  
                  //ContextCompat.checkSelfPermission(()-&gt; Context., Manifest.permission.ACCESS_NOTIFICATION_POLICY)
  
  
                  startActivity(intent);
  
                  }
              }
          }
      }
  </code></pre>
  <p>Class MyAlarm.java this is where my receiver is.</p>
  <pre><code>package com.example.myapplication;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.util.Log;
  
  public class MyAlarm extends BroadcastReceiver {
  
      public void onReceive(Context context, Intent intent) {
          MainActivity.changeInterruptionFilter(2);
          //you can check the log that it is fired
          //Here we are actually not doing anything
          //but you can do any task here that you want to be done at a specific time everyday
          Log.d(&quot;MyAlarm&quot;, &quot;Alarm just fired&quot;);
  
          }
      }
  </code></pre>
  <p>AndroidManifest.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.example.myapplication&quot;&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_NOTIFICATION_POLICY&quot;/&gt;
      &lt;uses-permission android:name=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot;/&gt;
      &lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_NOTIFICATION_POLICY&quot; /&gt;
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/Theme.MyApplication&quot;&gt;
          &lt;activity
              android:name=&quot;.MainActivity&quot;
              android:label=&quot;@string/app_name&quot;
              android:theme=&quot;@style/Theme.MyApplication.NoActionBar&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
  
          android:enabled=&quot;false&quot;&gt;
  
          android:enabled=&quot;false&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;!-- registering the receiver --&gt;
          &lt;receiver
              android:name=&quot;.MyAlarm&quot;
              android:enabled=&quot;true&quot;
              android:exported=&quot;true&quot; /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  ```
  </code></pre>