如何通过通知将字符串数组从BroadcastReceiver传递给Activity类
问题描述:
我想将广播接收器中的字符串传递给活动。当我点击通知时,我提出了一个通知。我开始在该活动的活动我想显示字符串数组值:如何通过通知将字符串数组从BroadcastReceiver传递给Activity类
我写一个类广播接收器的,如下图所示:如图所示
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类中获得。
请任何机构帮助我
答
您应该使用Intent.putStringArrayListExtra()
功能这一点。这里是例子:
ArrayList<String> strings = new ArrayList<String>();
strings.add("item1");
...
strings.add("itemN");
notificationIntent.putStringArrayListExtra("stringArrayArg", strings);
这里我怎样才能得到在ExampleActivity.class.please的字符串可以给你清晰的字符串在另一个活动 –