Wyjaśnienia dotyczące realizacji WakefulIntentService

CommonsWakefulIntentService działa pięknie, ale jest kilka rzeczy, których nie rozumiem. Poniżej znajduje się rdzeń usługi - okrojona wersjaźródło :

class WIS extends IntentService {

    private static final String NAME = WIS.class.getName() + ".Lock";
    private static volatile WakeLock lockStatic = null;

    synchronized private static PowerManager.WakeLock getLock(Context context) {
        if (lockStatic == null) {
            PowerManager mgr = (PowerManager) context
                    .getSystemService(Context.POWER_SERVICE);
            lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME);
            lockStatic.setReferenceCounted(true);
        }
        return (lockStatic);
    }

    public static void startWIS(Context ctxt, Intent i) {
        getLock(ctxt.getApplicationContext()).acquire();
        ctxt.startService(i);
    }

    public WIS(String name) {
        super(name);
        setIntentRedelivery(true);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        PowerManager.WakeLock lock = getLock(this.getApplicationContext());
        if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) { // ?
            lock.acquire();
        }
        super.onStartCommand(intent, flags, startId);
        return (START_REDELIVER_INTENT);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        try {
            // do your thing
        } finally {
            PowerManager.WakeLock lock = getLock(this.getApplicationContext());
            if (lock.isHeld()) lock.release();
        }
    }
}

pytania

Co się stanie, jeśli proces zostanie zabity tuż poonReceive() wraca nasz odbiornik alarmowy? To jest, jeśli usługaonCreate() (jeśli usługa nie jest jeszcze utworzona) lubonStartCommand() nigdy nie uciekaj. AFAIK zabity proces zabiera ze sobą zamki. Czy jest to niemożliwy scenariusz?W świetle poprzedniego powinien(flags & START_FLAG_RETRY) być dodany ?Dlaczegoif (!lock.isHeld()) sprawdzić?Dlaczego jestthis.getApplicationContext() potrzebne ? nie jestthis dość ?

questionAnswers(2)

yourAnswerToTheQuestion