如何通过Notification将字符串数组从BroadcastReceiver传递到Activity类
我想将一个字符串从广播接收器传递到活动。当我点击通知时,我已发出通知。我正在该活动中启动一个活动,我想显示字符串数组值:
我已经编写了一个 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 活动。当我单击“通知”时,我希望获得 RepeatingAlarm 类 arra[] 将在 CustomDialogExample 类中获得。
请任何人帮助我
I would like to pass a string from broadcast receiver to activity. I have raised a notification when I clicked on notification. I am starting an activity in that activity I would like to show string array values:
I have write a class of BroadcastReceiver as shown below:
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();
}
}
I have write a method for get the notification as shown below
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);
}
From the above method I am starting CustomDialogExample activity. When I clicked on Notification I would like to get the RepeatingAlarm class arra[] will get in CustomDialogExample class.
please any body help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用
Intent.putStringArrayListExtra()
函数。这是示例:You should use
Intent.putStringArrayListExtra()
function for this. Here is example: