我是第一次使用alarmManager的新手anodroid开发人员,但广播接收器似乎正在调用。
下面是创建alarmManager的代码
AlarmManager alarm=(AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(this,AlarmReciever.class);
PendingIntent p=PendingIntent.getBroadcast(this, 22, i,PendingIntent.FLAG_CANCEL_CURRENT);
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,1,p);
和广播接收器类
Public class AlarmReciever extends BroadcastReceiver{
@Override
public void onReceive(Context c, Intent i) {
// TODO Auto-generated method stub
Toast toast1= Toast.makeText(c, "This text will be displayed \n on the toast", Toast.LENGTH_LONG);
toast1.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
toast1.show();
}
}
答案 0 :(得分:1)
您是否在清单中添加了以下代码?
<receiver
android:name="AlarmReceiver"
android:process=":remote" >
</receiver>