title: A listener to a fragment without calling the fragment in android
body: <p>Im calling a fragment(ImageFraggment) from an actvity(MainActivity) , and created a interface on that fragment. And also i have implement Listner in Main activity. you can  see the code below.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements ImageFragment.imageEventListener  {
  
     //Calling ImageFragment
  
      @Override
      public void eventListner(int number) {
          log.d("MainActivity",number);
  
      }
  }
  </code></pre>
  
  <p>ImageFragment.java</p>
  
  <pre><code>public class ImageFragment extends Fragment {
      private imageEventListener imageEventListener;
  
  
    //enter a number
    //if number equal to 1
    {
      imageEventListener.eventListner(number);
    }
  
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
          try {
              imageEventListener = (imageEventListener) activity;
          } catch (ClassCastException e) {
              throw new ClassCastException(activity.toString() + " must implement imageEventListener");
          }
  
  
      }
  
  
      public interface imageEventListener {
          void eventListner(int number);
      }
  }
  </code></pre>
  
  <p>This code works fine, means when user enters 1,log will display it(from mainActivity).</p>
  
  <p>But now im trying to Listen to same event from another activity(AnotherActivity)(which doesnot call ImageFragment) as shown in below code.</p>
  
  <p>AnotherActivity.java</p>
  
  <pre><code>public class AnotherActivity extends AppCompatActivity implements ImageFragment.imageEventListener  {
     //I dont call imageFragment here    
       @Override
       public void eventListner(int number) {
           log.d("AnotherActivity",number);
  
       }
   }
  </code></pre>
  
  <p>But im unable to print the number using log, How can i resolve this?I'm missng any major thing here?</p>