0

I am developing a simple android app that manages events(An event contains a name, a description, and a date). For example: Somebody's birthday or something like that.

I want a canvas to pop up by itself at the specified date(even if I'm not in the application). I managed to create a Toast using AlarmManager and BroadcastReceiver which pop ups automatically at the specified date. But I can only write text to a Toast. Is there any way to create a canvas that will pop up similar to a Toast?

My alarm manager:

AlarmManager alarms = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE);


IntentFilter filter = new IntentFilter("ALARM_ACTION");
registerReceiver(receiver, filter);

Intent intent = new Intent("ALARM_ACTION");
intent.putExtra("param", "It's your mom's birthday!");
PendingIntent operation = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

alarms.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+1000,operation) ;

And my Receiver class:

public class Receiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //I want to replace the Toast with a canvas.
        Toast.makeText(context, intent.getStringExtra("param"), Toast.LENGTH_SHORT).show();        
    }
}
Bill Jobs
  • 25
  • 7
  • Please check the following link: [toast](http://stackoverflow.com/questions/11288475/custom-toast-in-android-a-simple-example) – wake-0 May 25 '16 at 15:25
  • And how can I create that custom toast in my Receiver class? Because it's not an activity and I can't call methods like findViewById for example. – Bill Jobs May 25 '16 at 15:41
  • @BillJobs you have a `Context` parameter. Which means you can get a `LayoutInflator` using `getSystemService()` and inflate any view you want. The view allows you to call `findViewById()` on to customize it. And then you can pass the View to the Toast. – adelphus May 25 '16 at 15:49

0 Answers0