Code example for SparseArray

Methods: delete, indexOfValue, keyAt, size

0
        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, alarm.mAlaramSender);
    } 
 
    /*package*/synchronized void cancelAlarm(Alarm alarm) {
        mAlarmManager.cancel(alarm.mAlaramSender);
        int index = mAlarms.indexOfValue(alarm);
        if (index >= 0) {
            mAlarms.delete(mAlarms.keyAt(index));
        } 
 
        // Unregister the BroadcastReceiver if there isn't a alarm anymore. 
        if (mAlarms.size() == 0) {
            mContext.unregisterReceiver(this);
        } 
    } 
 
    private static int sNextId = 0;
 
    private static synchronized int nextId() { 
        return sNextId++;
    }