我有一個調用AlarmManagerAlarmManager燒製模擬器但不是在物理設備
Intent intent;
intent = new Intent(context, MyEventReceiver.class);
PendingIntent appIntent = PendingIntent.getBroadcast(context, 0,
intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
appIntent);
,並在Manifiest我有強制性條目
<receiver android:name=".MyEventReceiver"
android:process=":remote" />
MyEventReceiver看起來像這樣
public class MyEventReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
try
{
// DO SOME WORK
}
catch (Exception e)
{
Log.e("MyEventReceiver", e.getMessage().toString());
}
}
}
應用
當報警被激活MyEventReceiver應該開始做一些事情EV如果我的應用程序沒有運行。在仿真器中,情況是這樣,但在實際設備上情況並非如此。
作爲一個例子,我將開始在模擬器上所有MyApplication和DDMS我可以看到所有MyApplication運行的進程。從MyApplication中添加一個警報,然後在DDMS中終止MyApplication的過程。當警報觸發MyEventReceiver完成它的工作並且在DDMS中看到兩個進程MyApplication和MyApplication:remote。
在實際的設備如果我開始爲MyApplication,添加一個報警,在時機成熟時進行報警,以執行什麼也沒有發生,然後殺死使用任務殺手的過程。如果我將設備連接到調試器並使用DDMS而不是設備上的任務殺手程序停止進程,則警報將會觸發並按預期工作。
有人可以幫助我瞭解爲什麼發生這種情況?我的印象是,一旦警報被安排好,除非設備重新啓動,否則它會持續存在。設備在警報執行時醒來。
我已經看到了這個':remote'這裏,那裏。什麼是用於什麼時候我們需要什麼? – Pentium10 2010-06-27 19:19:59
謝謝你的答案馬克 – JDM 2010-06-27 19:20:01
@ Pentium10:它迫使部分(在這種情況下,'BroadcastReceiver'),以從其他組件不同的進程中運行。考慮到大多數Android設備在RAM上有多緊張,我知道爲什麼SDK應用程序應該使用它。 – CommonsWare 2010-06-27 20:07:51