I want to throw an alarm intent after certain minutes. From this intent some data is received and a view from the app shoud show it.
This code is in the activity
public class MainActivity extends Activity{
DatePicker pickerDate;
TimePicker pickerTime;
Button buttonSetAlarm;
TextView info;
...
private void setAlarm(){
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+1000, pendingIntent);
}
Then the broadcast receiver, in the Activity class or outside in a separated java file ( see end of post ) , looks like this:
public class AlarmReceiver extends BroadcastReceiver {
private static final int MY_NOTIFICATION_ID=1;
NotificationManager notificationManager;
Notification myNotification;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm received!", Toast.LENGTH_LONG).show();
String information = getInformation();
info.setText("this is your info"+information); <--------------------
}
}
How can this be done ?
I've tryed to get the view from the context by inflating , that was unsuccesfull
following android - How to get view from context? and
I've also tryed to get the view from a bundle inside the intent but it seems that only strings and serializable objects can be passed by them.
If i Inner the broadcastreceiver in the activity , the alarm is not thrown ( No toast message appears, no changes in the textview ) described in : Calling SetContentView() from broadcast receiver althought it seems that this solutions don't work as said in : BroadcastReceiver as inner class
Thank you in advance !
L.