首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过通知将字符串数组从BroadcastReceiver传递到Activity类

如何通过通知将字符串数组从BroadcastReceiver传递到Activity类
EN

Stack Overflow用户
提问于 2011-08-27 19:32:31
回答 1查看 1.3K关注 0票数 1

我想将一个字符串从广播接收器传递到activity。当我点击通知时,我提出了一个通知。我正在启动一个活动,在该活动中,我想显示字符串数组值:

我已经编写了一个BroadcastReceiver类,如下所示:

代码语言:javascript
复制
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();

       }

   }

我已经编写了一个获取通知的方法,如下所示

代码语言:javascript
复制
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时,我想要获取arra[]将在CustomDialogExample类中获得的RepeatingAlarm类。

请任何人帮助我

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-27 19:41:48

为此,您应该使用Intent.putStringArrayListExtra()函数。下面是一个例子:

代码语言:javascript
复制
 ArrayList<String> strings = new ArrayList<String>();
 strings.add("item1");
 ...
 strings.add("itemN");
 notificationIntent.putStringArrayListExtra("stringArrayArg", strings);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7214252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档