我想将广播接收器中的字符串传递给活动。我点击通知后发出了通知。我正在该活动中开始一项活动,我希望显示字符串数组值:
我已经编写了一个BroadcastReceiver类,如下所示:
public class RepeatingAlarm extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
String array[5]={"hai","hello","how r u?","welcome"};
//i am calling notification method here
notification();
}
}
我已经写了一个获取通知的方法,如下所示
public static void myNotify(Context context,String message)
{
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,"A new notification", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(""));
Intent notificationIntent = new Intent(context.getApplicationContext(), CustomDialogExample.class);// i am starting CustomDialogExample
PendingIntent activity = PendingIntent.getActivity(context,0,notificationIntent, 0);
notification.setLatestEventInfo(context,"Notification for you",message,activity);
notification.number += 1;
notificationManager.notify(0, notification);
}
从上面的方法我开始CustomDialogExample活动。当我点击Notification时,我想获得RepeatingAlarm类arra []将进入CustomDialogExample类。
请任何人帮助我
答案 0 :(得分:4)
您应该使用Intent.putStringArrayListExtra()
功能。这是一个例子:
ArrayList<String> strings = new ArrayList<String>();
strings.add("item1");
...
strings.add("itemN");
notificationIntent.putStringArrayListExtra("stringArrayArg", strings);