我有一个需要启动和停止活动的应用程序。
到目前为止,我们可以启动 Activity。
当我尝试停止活动时,问题就来了。
这是广播意图关闭活动的 AlarmManager:
Intent ftue = new Intent(ctxt, VideoActivty.class);
ftue.putExtra("finish", true);
PendingIntent pftue = PendingIntent.getBroadcast(ctxt, 0, ftue, 0);
Calendar calSet4 = Calendar.getInstance();
calSet4.set(Calendar.MONTH, c.get(Calendar.MONTH));
calSet4.set(Calendar.YEAR, c.get(Calendar.YEAR));
calSet4.set(Calendar.DAY_OF_WEEK, 3);
calSet4.set(Calendar.HOUR_OF_DAY, hftue);
calSet4.set(Calendar.MINUTE, mftue);
calSet4.set(Calendar.SECOND, 0);
calSet4.set(Calendar.MILLISECOND, 0);
//calSet.setTimeZone(TimeZone.getTimeZone("UTC"));
mgr.setRepeating(AlarmManager.RTC_WAKEUP, calSet4.getTimeInMillis(),
7 * 24 * 60 * 60 * 1000, pftue);
在我的 Activty 中,我实现了一个应该关闭 Activty 的 BroadcastReceiver。
@Override
public void onResume() {
super.onResume();
IntentFilter f=new IntentFilter();
registerReceiver(receiver, f);
}
@Override
public void onPause() {
unregisterReceiver(receiver);
super.onPause();
}
BroadcastReceiver receiver=new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.e("","intento ricevuto");
if(intent.getBooleanExtra("finish",false))finish();
}
};
我的应用程序没有收到广播的意图,我知道这是因为意图过滤器是空的。
请问我应该如何实现意图过滤器来接收广播?
谢谢!