出于某种原因,我想让AlarmManager在同一个代码文件中调用广播接收器,所以我做了类似的事情:
AlarmManager oAlarmManager;
PendingIntent oPendingIntentAlarm;
Intent intentAlarm = new Intent(this, clsMyReceiver.class);
oPendingIntentAlarm = PendingIntent.getBroadcast(this, 0, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
oAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
oAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+5000, oPendingIntentAlarm); //Execute in 5 seconds for testing
然后,在同一个文件中我有:
public class clsMyReceiver extends BroadcastReceiver
{
@Override public void onReceive(Context context, Intent intent)
{ //This is never reached
}
}
我已经在Manifest中声明了这样:
<receiver
android:name=".clsMyReceiver"
android:process=":remote" >
</receiver>
但正如我所说,广播中的OnReceive永远不会被触发。有什么建议吗?