如果没有人打电话,一切都很好。如果我使用Opera,Gmail或其他应用程序,它就可以了。并及时启动目标警报意图。
Intent i2 = new Intent();
i2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, i2, 0);
curtimeset = System.currentTimeMillis();
am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, curtimeset + full, pIntent); //full time in mills when alarm will be on even from lock mode
当定时器启动和当前时间等于目标时间时。应用开始意图。从前台加载它。
public void instanceinitiale() {
Intent resumeIntent = new Intent(getApplicationContext(), Main.class);
resumeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(resumeIntent);
}
如果在任何情况下如何加载我的闹钟?)
答案 0 :(得分:0)
当需要报警时,系统会调用您的应用程序。系统会向您发送相同的意图(您在创建警报时使用)。如果你在创建数据时放入数据,你可以得到它
public class AlarmService extends BroadcastReceiver {
private final static String action="android.intent.action.ALARMHANDLERACTIVITY";
public AlarmService(){
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().compareTo(action)==0){
context.startActivity(intent);
}
}
public void createAlarm(){
Intent intent=new Intent("android.intent.action.ALARMHANDLERACTIVITY");
intent.putExtra("eventID", Integer.valueOf(id));
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, intent,0);
AlarmManager aManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
aManager.set(AlarmManager.RTC_WAKEUP, temp.getStartDate().getTimeInMillis(), pendingIntent);
}
}
将接收器定义为清单的应用程序块:
<receiver android:name=".alarmService.AlarmService">
<intent-filter android:priority="200">
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>