Can a BroadcastReceiver pass control to a Activity?
Can a BroadcastReceiver pass control to a Activity?
Maybe I am thinking about this in the wrong way but I have a BroadcasterReceiver waiting for a SMS message to come in. once it comes in I would like it to pass control to a Activi开发者_开发知识库ty so the Activity can set a alarm and beep. but the following code will not build inside the BroadcastReceiver
Intent intent = new Intent(PhoneFinder.class, AlarmService.class);
startActivity(intent);
An explicit Intent like the one you've written takes a Context and the class you want to launch as parameters, not two class names. The onReceive() method, where you are probably attempting this, passes you a context parameter that you can use to do this.
public void onReceive(Context context, Intent intent) {
//Launch Activity
Intent startIntent = new Intent(context, PhoneFinder.class);
startActivity(startIntent);
}
This will launch PhoneFinder when a broadcast is picked up by the receiver.
Hope that Helps!
精彩评论