由于片段旨在封装逻辑,我决定将 BroadReceiver 逻辑放在我自己的片段中。
起初我设置了一个警报,就像它在 ApiDemos 中显示的那样:
Intent intent = new Intent(getActivity(),OnAirPresentBroadcastReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 30);
AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
OnAirPresentBroadcastReceiver 接收广播,此广播的目的是更新片段的 UI。我被困在这里 - 有可能吗?如何?