title: Async Task inside BroadcastReceiver onReceive method not running?
body: <p>I have a working app which sends String data from application's input textfield to TCP server on my PC. 
  I have added BroadcastReceiver class to send message to computer when it's received.
  Application receives messages(Toast is working), but I can't make it send received message to PC.  </p>
  
  <p>No Errors. Application just skips methods called.</p>
  
  <p>How Do I Call a method inside onReceive?</p>
  
  <p>Thank You for any help!</p>
  
  <pre><code>public class SmsReceiver extends BroadcastReceiver {
  String phone;
  String message;
  
  @Override
  public void onReceive(Context context, Intent intent) {
      Bundle intentExtras = intent.getExtras();
  
      if (intentExtras != null) {
          // Get Messages
          Object[] sms = (Object[]) intentExtras.get("pdus");
  
          for (int i = 0; i &lt; sms.length; ++i) {
              // Parse Each Message
              SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
  
              phone = smsMessage.getOriginatingAddress();
              message = smsMessage.getMessageBody().toString();
              System.out.println("Message is: "+message);
              Log.i("sth","message "+message);
  
              //What i have tried
              sendMessage(message);
  
              //creating instance
              MessageSender messageSender = new MessageSender();
              messageSender.execute(message);
  
              //calling metod from MainActivity
              ((MainActivity)context.getApplicationContext()).send2(message);
  
              MainActivity.send2(message);
  
              //toast is working fine
              Toast.makeText(context,"Alert:"+ phone + ": " + message, Toast.LENGTH_SHORT).show();
          }
      }
  }
  public void sendMessage(String s)
  {
      MessageSender messageSender = new MessageSender();
      messageSender.execute(s);
  }
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  EditText e1;
  
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      e1 = (EditText)findViewById(R.id.editText);
      //This works
      MessageSender messageSender = new MessageSender();
      messageSender.execute("App launched!");
  }
  
  //On Button click. Working good.
  public void send(View v)
  {
      MessageSender messageSender = new MessageSender();
      messageSender.execute(e1.getText().toString());
  }
  //For test purposes
  public static void send2(String s)
  {
      MessageSender messageSender = new MessageSender();
      messageSender.execute(s);
  }
  </code></pre>
  
  <p>MessageSender</p>
  
  <pre><code>public class MessageSender extends AsyncTask&lt;String,Void,Void&gt;
  {
  Socket s;
  DataOutputStream dos;
  PrintWriter pw;
  
  @Override
  public Void doInBackground(String... voids) {
  
      String message = voids[0];
  try {
      s = new Socket("192.168.1.69", 7800);
      pw = new PrintWriter(s.getOutputStream());
      pw.write(message);
      pw.flush();
      pw.close();
      s.close();
  
  }catch(IOException e)
  {
      e.printStackTrace();
  }
      return null;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Added server code:</p>
  
  <pre><code>  public class MyServerFrame extends javax.swing.JFrame 
    {
    static Socket s;
     static ServerSocket ss;
    static InputStreamReader isr;
    static BufferedReader br;
    static String message;public MyServerFrame() 
   {
  
  }
  
  public static void main(String args[]) 
  {   
      try 
      {
          ss = new ServerSocket(7800);
          while(true)
          {
              s=ss.accept();
              isr = new InputStreamReader(s.getInputStream());
              br = new BufferedReader(isr);
              StringBuilder everything = new StringBuilder();
              String line;
              while( (line = reader.readLine()) != null) 
              {
                 everything.append(line);
              }
              message = everything.toString();//multiple to onelinestring 
              System.out.println(message);
          }   
      }catch (IOException e) 
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>