Transfer data between BroadCast and Activity
how can i transfer data from BroadcastReceiver to activity? I tried it with intent but it's returning null.
MyBroadcastReceiver class:
public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "MyBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
......................................
......................................
String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Intent i = new Intent(context, CalendarCall.class);
i.putExtra("number", phoneNumber);
开发者_运维问答 (startActivity(i)-> i can't start Activity under BroadcastReceiver,what is another way to do that? )
Log.d(TAG, phoneNumber);
}
}
}
}
Main Activity:
Intent intent = getIntent();
String number = intent.getStringExtra("number");
Log.d(TAG, "Number: " + number);
MyBroadcastReceiver class:
public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "MyBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
......................................
......................................
String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Intent i = new Intent(context, CalendarCall.class);
i.putExtra("number", phoneNumber);
context.startActivity(i);
Log.d(TAG, phoneNumber);
}
}
}
}
try this code
精彩评论