title: Accessing main activity in Broadcast Reciever without using intent
body: <p>I am stuck in a problem. I have a broadcast receiver that calls the method of class takes in context and main activity reference in constructor. I dont know how to access main activity in broadcast receiver.Here is my code:</p>
  
  <pre><code>public void onReceive(@NonNull Context context, @NonNull Intent intent) {
          if (context == null) {
              throw new IllegalArgumentException();
          }
          ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo info = cm.getActiveNetworkInfo();
  
          if (info != null) {
              if (info.isConnected()) { 
                  if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                       Class myclass = new Class(context,mainactivity reference); //dont know how to get main activity here
                  }
  
              }
          }
      }
  </code></pre>
  
  <p>Is there is any way that I can get it without Intent or there is some other method. I am in learning phase any help will be appreciated.</p>
  
  <p>In manifest:</p>
  
  <pre><code>&lt;receiver android:name="myreceiver"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt; 
  </code></pre>