【发布时间】:2012-03-12 19:20:29
【问题描述】:
场景:
我有一个警报计划在指定的时间内运行。每次执行时,我的 BroadCastReceiver 都会触发。
在 BroadCastReceiver 中,我进行了各种检查,最终得到一个纯字符串的 ArrayList
我在状态栏上显示通知
当用户点击通知时,我会显示一个活动。我需要在我的 Activity 中使用 ArrayList 将其显示在视图上。
这里是示例代码:
public class ReceiverAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ArrayList<String> notifications = new ArrayList<String>();
//do the checks, for exemplification I add these values
notifications.add("This is very important");
notifications.add("This is not so important");
notifications.add("This is way too mimportant");
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//init some values from notificationManager
Intent intentNotif = new Intent(context, NotificationViewer.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intentNotif, 0);
Notification notification = new Notification(icon, text, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
}
还有
public class NotificationViewer extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notification_viewer);
//HERE I NEED the ArrayList<String> notifications
}
我尝试了我发现的大部分东西,从捆绑包到 putStringArrayListExtra(),但没有任何效果。在我的活动中,我找不到检索数据的方法。 请帮助我,因为我被卡住了。
【问题讨论】:
-
你是在 intentNotif 还是 contentIntent 上设置 extras 吗?
-
我在 intentNotif 上尝试过的附加功能
标签: android android-activity arraylist broadcastreceiver bundle