我正在开发一个管理事件的简单Android应用程序(一个事件包含一个名称,一个描述和一个日期)。例如:某人的生日或类似的东西。
我希望画布在指定日期自行弹出(即使我不在应用程序中)。我设法使用AlarmManager和BroadcastReceiver创建Toast,它在指定日期自动弹出。但我只能写一个Toast的文字。 有没有办法创建一个类似于Toast的画布?
我的警报管理器:
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) ;
我的接收器类:
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();
}
}