Java 有意将数据从活动传递到广播接收器

Java 有意将数据从活动传递到广播接收器,java,android,broadcastreceiver,android-notifications,Java,Android,Broadcastreceiver,Android Notifications,我正在通过BroacastReciever在特定时间安排通知。我想将数据从通知单击传递到活动的newIntent方法。到目前为止,一切都很顺利,通知也顺利通过。但是,我在将数据从活动传递到BrocastReceiver类时遇到了一个问题。 问题是我传递的变量出现在我的活动类中,而不是在广播接收器中。我不知道如何将这些数据输入我的receiver类 Activity.java private void setTimer(String place){ AlarmManager ala

我正在通过
BroacastReciever
在特定时间安排通知。我想将数据从通知单击传递到活动的
newIntent
方法。到目前为止,一切都很顺利,通知也顺利通过。但是,我在将数据从
活动
传递到
BrocastReceiver
类时遇到了一个问题。 问题是我传递的变量出现在我的
活动
类中,而不是在
广播接收器
中。我不知道如何将这些数据输入我的receiver类

Activity.java

private void setTimer(String place){
        AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(this, BroadcastAlarm.class);
        intent.setAction("MY_NOTIFICATION_MESSAGE");
        intent.putExtra("place", place); //this doesn't send data to notification. I want to send place string to notification
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    }
  @Override
    public void onReceive(Context context, Intent intent) {

  Intent intent1 = new Intent(context, SearchActivity.class);
intent1.putExtra("place", stringNotHere); //if I send data from here it gets available but the problem is that my place data is on my activity class not here
   intent1.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder notification= new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
        notification.setContentIntent(pendingIntent)
    }
BroadcastReceiver.java

private void setTimer(String place){
        AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(this, BroadcastAlarm.class);
        intent.setAction("MY_NOTIFICATION_MESSAGE");
        intent.putExtra("place", place); //this doesn't send data to notification. I want to send place string to notification
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    }
  @Override
    public void onReceive(Context context, Intent intent) {

  Intent intent1 = new Intent(context, SearchActivity.class);
intent1.putExtra("place", stringNotHere); //if I send data from here it gets available but the problem is that my place data is on my activity class not here
   intent1.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder notification= new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
        notification.setContentIntent(pendingIntent)
    }
如您所见,我需要在
BroadcastReceiver
上设置活动的
place
变量。如何执行此操作?

替换:

intent1.putExtra("place", stringNotHere);
为此:

String place = intent.getStringExtra("place");
intent1.putExtra("place", place);