title: Sending Extra Message between Service and BroadcastReceiver
body: <p>In my app I have TextField and button. When clicked, Service starts and reads value from TextField and triggers <code>AlarmManager</code>. After few seconds Service starts <code>BroadcastReceiver</code> and <code>BrodcastReceiver</code> start Second <code>Activity</code>.</p>
  
  <p><code>Activity</code> informs Service and sends value. I can see <code>Toast</code> with correct number in <code>Service</code>. But in Second <code>Activity</code> I see only the value that was entered for the first time.</p>
  
  <p>For example: I wrote 5 and it's count to 5 and start BroadcatsReceiver and in Activity I can see 5. But if I will put right now 3, it will count to 3, but in secound activity show 5(example on the picture below). Next: I puts 8 it's count to eight, show correctly first Toast. In Secound activity still: 5. Even if I will upload program on phone one more time. Only way to see correct value is to delete application and starts it one more time. How can I fix it?</p>
  
  <p>Method in MainActivity:</p>
  
  <pre><code>public void ClickStart(View view) {
          Intent i = new Intent(this, MyService.class);
          EditText numerField = (EditText) findViewById(R.id.numerField);
          String message = numerField.getText().toString();
          i.putExtra("EXTRA_MESSAGE", message);
          this.startService(i);
      }
  </code></pre>
  
  <p>MyService:</p>
  
  <pre><code>public class MyService extends Service {
      @Override
      public void onStart(Intent intent, int startId) {
  
          int countTime = 10;
          String data = (String) intent.getExtras().get("EXTRA_MESSAGE");
         countTime = Integer.parseInt(data);
  
          Intent i = new Intent(this, MyReciver.class);
          i.putExtra("EXTRA_MESSAGE", data);
          Log.d("dddService", data);  // Correct data
  
          Toast tosty = Toast.makeText(this, data + " sec", Toast.LENGTH_SHORT);
          tosty.show();           
  
          PendingIntent pintent = PendingIntent.getBroadcast(
                  this.getApplicationContext(), 1, i, 0);
  
          AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
          alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                  + (countTime * 1000), pintent);
  
      }
  </code></pre>
  
  <p>MyReceiver:</p>
  
  <pre><code>public void onReceive(Context arg0, Intent arg1) {
  
  
          String data = (String) arg1.getExtras().get("EXTRA_MESSAGE");
          Log.d("ddd", data);  //wrrong data
          Intent i = new Intent(arg0, MyActivity.class);
          i.putExtras(arg1.getExtras());
          i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  
          arg0.startActivity(i);  
      }
  </code></pre>
  
  <p>My activity:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          String message = getIntent().getStringExtra("EXTRA_MESSAGE");
  
          Toast.makeText(getApplicationContext(), message + " Activity", Toast.LENGTH_SHORT)
                  .show();
  
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/MS96q.png" alt="Example. LogCat"></p>