【发布时间】:2014-04-05 03:52:13
【问题描述】:
我有一个广播接收器类,它进入一个数组列表并根据每个对象的时间设置多个挂起的意图,尽管只有最后一个挂起的意图集在启动后显示我使用不同的计数值来确保请求代码是不同的,但只有在我的循环中设置的最后一个待处理的意图仍然显示
public class AutoStartNotifyReceiver extends BroadcastReceiver {
private PendingIntent pendingIntent;
Calendar current = Calendar.getInstance();
ArrayList<appointment> myArray;
private final String BOOT_COMPLETED_ACTION = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(BOOT_COMPLETED_ACTION)){
FileInputStream input = null;
ObjectInputStream inputob = null;
try {
input = context.getApplicationContext().openFileInput("app.ser");
inputob = new ObjectInputStream(input);
myArray = (ArrayList<appointment>) inputob.readObject();
inputob.close();
input.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
int count = 0;
for(appointment cals: myArray)
{
if(cals.gettimeofappt()>current.getTimeInMillis())
{
count ++;
Intent myIntent = new Intent(context, MyAlarmService.class);
pendingIntent = PendingIntent.getService(context, count, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cals.gettimeofappt(), pendingIntent);
}
}
}
}
}
【问题讨论】:
标签: android android-pendingintent