I have a BroadcastReceiver which gets data from Activity by Intent, with PendingIntent. The code work fine but when i'm restarting my device and onReceive calling i am getting Error... I don't know what the error because he appear after my phone restarting and the logchat cannot notice the phone and i don't see the error...
Activity:
Intent intent = new Intent(addOne.this,AlarmReceiver.class);
intent.putExtra("msg", title.getText().toString());
intent.putExtra("note", note.getText().toString());
AlarmManager alarmMgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
Receiver:
String msg=intent.getStringExtra("msg");
String note=intent.getStringExtra("note");
Intent startIntent = new Intent(context, alarmDialog.class);
startIntent.putExtra("msg",msg);
startIntent.putExtra("note",note);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startIntent);
Manifest:
<receiver android:name=".AlarmReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I tried change the FLAG to FLAG_CANCEL_CURRENT still nothing changed. Thanks for helping.
I think, may be there where error comes due to activity not starting after restart your phone and receiver still try to receive your string messages.
I don't know, How you can solve your this problem. when your phone restart your receiver gets null value. Try to use shared preference or String buffer to store your receiver String value.
remove this code
try this
and specify this action in manifest file which is your receiver like this
Now make change your receiver code with code
You have set action
Intent.ACTION_BOOT_COMPLETED
, With above code you your sharedpreference string get and pass with intent toalarmDialog.class
when your device boot is complete.you have specified this action in your manifest file so now no need to do second time. try this code. Try this .