我想从BroadcastReceiver
开始Activity
。我怎么能这样做?
答案 0 :(得分:9)
定义您的BroadcastReceiver:
private final BroadcastReceiver receiver
= new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Do something
}
};
在onResume中注册您的接收器:
@Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction("SOME_ACTION");
registerReceiver(receiver, filter);
}
在onPause中取消注册接收器:
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiver);
}