开发者

how to pass a string array from BroadcastReceiver to Activity class through Notification

开发者 https://www.devze.com 2023-03-31 08:32 出处:网络
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 a

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


You should use Intent.putStringArrayListExtra() function for this. Here is example:

 ArrayList<String> strings = new ArrayList<String>();
 strings.add("item1");
 ...
 strings.add("itemN");
 notificationIntent.putStringArrayListExtra("stringArrayArg", strings);
0

精彩评论

暂无评论...
验证码 换一张
取 消