Reputation: 1862
I need pass a string array from AlarmReceiver.class to Notify.class but the string is always "null". Now, is a problem about intent within AlarmReceiver?
public class AlarmReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
[...]
Intent notificationIntent = new Intent("com.example.myapp", null, context, Notify.class);
notificationIntent.putExtra("notify", not1[x]);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notify class:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent notificationIntent = getIntent();
String[] message = notificationIntent.getStringArrayExtra("notify");
Toast toast6=Toast.makeText(this,""+message,Toast.LENGTH_LONG);
toast6.show();
Upvotes: 3
Views: 674
Reputation: 86948
You are using two different methods...
Here you're are working with one String:
notificationIntent.putExtra("notify", not1[x]); // Pass one String
You should read this "notify"
with:
String message = notificationIntent.getStringExtra("notify");
If you want to pass the array of Strings use:
notificationIntent.putExtra("notify", not1); // Pass array of Strings
You should read this with:
String[] message = notificationIntent.getStringArrayExtra("notify");
Do you see the difference?
Upvotes: 7