title: Displaying a message from BroadcastReceiver
body: <p>I wrote a simple class that extends BroadcastReceiver to handle an incoming call and get the caller's number. Now I want to display that number in a popup window or something similar. I've tried to display an alert dialog or open an activity but my app crashed. Then I read that it's not a good idea to start dialog from a BroadcastReceiver class. I need you to advice me how to correctly display the caller's number on the screen when there's an incoming call. This is my Broadcast Receiver class: </p>
  
  <pre><code>package com.example.nrsearch;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.telephony.PhoneStateListener;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  
  public class CallReceiver extends BroadcastReceiver {
      public CallReceiver() {
      }
  
  @Override
  public void onReceive(Context context, Intent intent) {
      Log.i("CallReceiverBroadcast", "onReceive() is called. ");
      TelephonyManager teleMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
      PhoneStateListener psl = new PhoneStateListener() {
          @Override
          public void onCallStateChanged(int state, String incomingNumber) {
              Log.i("CallReceiverBroadcast", "onCallStateChanged() is called. ");
              switch (state) {
              case TelephonyManager.CALL_STATE_RINGING:
                  Log.i("CallReceiverBroadcast", "Incoming call caught. Caller's number is " + incomingNumber + ".");
              }
          }
      };
      teleMgr.listen(psl, PhoneStateListener.LISTEN_CALL_STATE);
      teleMgr.listen(psl, PhoneStateListener.LISTEN_NONE);
  }
  }
  </code></pre>