title: how to send data from broadcast receiver to activity in android
body: <p>Here is what I want to do.  I have created a broadcastreceiver class which detects incoming calls through callrecieve activity. Now as soon as a call comes I want to find its current time and display it through another activity. I have used intents for this. But still I am not getting the time value as required, displayed when I receive a call. I have posted all the codes I am using. any help would be great</p>
  
  <p>Here is the broadcast receiver activity which checks the state of phone for incoming calls and is responsible for broadcasting the intent</p>
  
  <pre><code>package com.mohit;
  
  import android.app.Activity;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  
  
  public class callreceive extends Activity {
  public class receive extends BroadcastReceiver {
  
  
      long start_time,end_time,dif_sec;
      int flag=0;
  
    @Override
    public void onReceive(Context context, Intent intent) {
      Bundle extras = intent.getExtras();
      if (extras != null) {
        String state = extras.getString(TelephonyManager.EXTRA_STATE);
  
        Log.w("DEBUG", state);
        if ((state.equals(TelephonyManager.EXTRA_STATE_IDLE))&amp;&amp;flag==0) 
        {
          flag=1;
          start_time=System.currentTimeMillis();
          Intent intent1 = new Intent();//(callreceive.this,TestActivity.class);
          intent1.setAction(Intent.ACTION_SEND);
          intent1.putExtra("start_time",start_time);
          startActivity(intent1);
  
          }
      }
    }
  }
  }    
  </code></pre>
  
  <p>Now i want to send the value of start_time to an activity as soon as if loop is executed. Here is the code for the receiving activity-Test Activity.</p>
  
  <pre><code>package com.mohit;
  
  import com.mohit.R;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class TestActivity extends Activity {
  
      TextView output1,output2;
      long start_time,end_time;
      int flag=0;
      long dif_sec=0;
  
        @Override
          public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.main);
               output1=(TextView)findViewById(R.id.textView1);
  
  
               Intent extras = getIntent();
                if (extras!=null)
                {
  
                    if (flag==0)
                    {
                        flag=1;
                   dif_sec=extras.getLongExtra("start_time",0);
                    }
                }
                output1.setText(String.valueOf(dif_sec));
  
                }
  
  } 
  </code></pre>
  
  <p>Here is the android manifest file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.mohit"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk android:minSdkVersion="7" /&gt;
  &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
  
      &lt;application
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name" &gt;
      &lt;activity android:name="TestActivity" &gt;
          &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
          &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
  
              &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
  
       &lt;activity android:name="callreceive" &gt;
      &lt;receiver android:name="receive" &gt;
          &lt;intent-filter&gt;
      &lt;action android:name="android.intent.action.SEND" /&gt;
      &lt;action android:name="android.intent.action.PHONE_STATE"&gt;&lt;/action&gt;
      &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;/activity&gt;
  
   &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I am unable to print the value of start_time through test acitvity. Am I missing something or is something wrong?? Plz Help
  THanx</p>