Example usage for android.app Service START_NOT_STICKY

List of usage examples for android.app Service START_NOT_STICKY

Introduction

In this page you can find the example usage for android.app Service START_NOT_STICKY.

Prototype

int START_NOT_STICKY

To view the source code for android.app Service START_NOT_STICKY.

Click Source Link

Document

Constant to return from #onStartCommand : if this service's process is killed while it is started (after returning from #onStartCommand ), and there are no new start intents to deliver to it, then take the service out of the started state and don't recreate until a future explicit call to Context#startService Context.startService(Intent) .

Usage

From source file:com.BeatYourRecord.AssignmentSyncService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final int startId_ = startId;
    if (!isRunning) {
        isRunning = true;//  w ww  . j  av a2  s  . c  o m
    } else {
        Log.d(LOG_TAG, "sync service is already running, stop and return!!!");
        // For whatever reason, the previous onStartCommand is still running,
        // perhaps the service got
        // killed by runtime and this service is not STICKY, so it never reach end
        // to call stopSelf?
        // So just kill it and let another alarm to start it again.
        stopSelf(startId_);
        return Service.START_NOT_STICKY;
    }

    // Log.d(LOG_TAG, "incoming startId=" + startId_);
    // Log.d(LOG_TAG, "thread id=" + Thread.currentThread().getId());
    // Log.d(LOG_TAG, "thread count=" +
    // Thread.currentThread().getThreadGroup().activeCount());
    if ((flags & Service.START_FLAG_RETRY) == Service.START_FLAG_RETRY) {
        Log.d(LOG_TAG, "assignment service retry");
    }

    ytdDomain = intent.getStringExtra(DbHelper.YTD_DOMAIN);
    ytdJsonRpcUrl = "http://" + ytdDomain + "/jsonrpc";

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            stopSelf(startId_);
            Log.d(LOG_TAG, "startId=" + startId_ + " is finished.");
        }
    };

    new Thread() {
        @Override
        public void run() {
            String newAssignmentId = updateAssignmentDb();
            if (newAssignmentId != null) {
                Intent intent = new Intent();
                intent.setAction(MainActivity.NEW_ASSIGNMENT_UPDATE);
                intent.putExtra(DbHelper.YTD_DOMAIN, ytdDomain);
                intent.putExtra(DbHelper.ASSIGNMENT_ID, newAssignmentId);
                sendBroadcast(intent);
                sendNotification(ytdDomain, newAssignmentId);
            }

            handler.sendEmptyMessage(0);
        }
    }.start();

    return Service.START_NOT_STICKY;
}

From source file:com.kentdisplays.synccardboarddemo.FileDownloadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (!mFtpServiceBound) {
        bindToFtpService();/*from  w  w  w.  j ava 2  s .  c  o  m*/
    }
    return Service.START_NOT_STICKY;
}

From source file:com.google.samples.apps.iosched.feedback.FeedbackWearableListenerService.java

public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        String action = intent.getAction();
        if (SessionAlarmService.ACTION_NOTIFICATION_DISMISSAL.equals(action)) {
            String sessionId = intent.getStringExtra(SessionAlarmService.KEY_SESSION_ID);
            LOGD(TAG, "onStartCommand(): Action = ACTION_NOTIFICATION_DISMISSAL Session: " + sessionId);
            dismissWearableNotification(sessionId);
        }//from  w  ww .j a va 2 s. c om
    }
    return Service.START_NOT_STICKY;
}

From source file:com.razza.apps.iosched.feedback.FeedbackWearableListenerService.java

public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        String action = intent.getAction();
        if (SessionAlarmService.ACTION_NOTIFICATION_DISMISSAL.equals(action)) {
            String sessionId = intent.getStringExtra(SessionAlarmService.KEY_SESSION_ID);
            LogUtils.LOGD(TAG,//from   w  w w.  j  a  v  a2s .c  o  m
                    "onStartCommand(): Action = ACTION_NOTIFICATION_DISMISSAL Session: " + sessionId);
            dismissWearableNotification(sessionId);
        }
    }
    return Service.START_NOT_STICKY;
}

From source file:com.fairphone.updater.UpdaterService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    mSharedPreferences = getApplicationContext()
            .getSharedPreferences(FairphoneUpdater.FAIRPHONE_UPDATER_PREFERENCES, MODE_PRIVATE);

    if (isFileStillValid()) {
        checkVersionValidation(getApplicationContext());
    } else if (hasInternetConnection()) {
        // remove the old file if its still there for some reason
        removeLatestFile(getApplicationContext());

        setupDownloadManager();/*from  ww w .  j  av  a2  s. c om*/

        // start the download of the latest file
        startDownloadLatest();
    }

    return Service.START_NOT_STICKY;
}

From source file:com.qasp.diego.arsp.LocalizacaoGPSService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (checkPermission(getApplicationContext()))
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, INTERVALO_TEMPO, INTERVALO_DISTANCIA, ll);
    ultimamedicaoGPS = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    Long = ultimamedicaoGPS.getLongitude();
    Lat = ultimamedicaoGPS.getLatitude();
    return Service.START_NOT_STICKY;
}

From source file:org.uproxy.tun2socks.TunnelManager.java

public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(LOG_TAG, "onStartCommand");
    LocalBroadcastManager.getInstance(m_parentService).registerReceiver(m_broadcastReceiver,
            new IntentFilter(DnsResolverService.DNS_ADDRESS_BROADCAST));

    m_socksServerAddress = intent.getStringExtra(SOCKS_SERVER_ADDRESS_EXTRA);
    if (m_socksServerAddress == null) {
        Log.e(LOG_TAG, "Failed to receive the socks server address.");
        m_parentService.broadcastVpnStart(false /* success */);
        return 0;
    }/*from  w  ww .java  2 s  .  c o  m*/

    try {
        if (!m_tunnel.startRouting()) {
            Log.e(LOG_TAG, "Failed to establish VPN");
            m_parentService.broadcastVpnStart(false /* success */);
        }
    } catch (Tunnel.Exception e) {
        Log.e(LOG_TAG, String.format("Failed to establish VPN: %s", e.getMessage()));
        m_parentService.broadcastVpnStart(false /* success */);
    }
    return android.app.Service.START_NOT_STICKY;
}

From source file:com.miguelbcr.io.rx_gps_service.lib.RxGpsService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
    rxGpsPresenter.attachView(this);
    notificationFactory = new NotificationFactory(this, listener);

    startForeground(notificationFactory.getNotificationIdServiceStarted(),
            notificationFactory.getNotificationServiceStarted(0, 0));

    listener.onServiceAlreadyStarted();/*from   w ww  .  j  a  v a 2s . co m*/

    return Service.START_NOT_STICKY;
}

From source file:com.dotd.mgrs.gps.MGRSLocationListener.java

public int onStartCommand(Intent intent, int flags, int startId) {
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    sendMessageBroadcast(getString(R.string.acquiring));

    return Service.START_NOT_STICKY;
}

From source file:com.google.samples.apps.iosched.service.FeedbackListenerService.java

public int onStartCommand(Intent intent, int flags, int startId) {
    if (null != intent) {
        String action = intent.getAction();
        if (SessionAlarmService.ACTION_NOTIFICATION_DISMISSAL.equals(action)) {
            String sessionId = intent.getStringExtra(SessionAlarmService.KEY_SESSION_ID);
            LOGD(TAG, "onStartCommand(): Action = ACTION_NOTIFICATION_DISMISSAL Session: " + sessionId);
            dismissWearableNotification(sessionId);
        }//from   w w  w.  ja  va  2  s  .co  m
    }
    return Service.START_NOT_STICKY;
}