Example usage for android.app Service START_STICKY

List of usage examples for android.app Service START_STICKY

Introduction

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

Prototype

int START_STICKY

To view the source code for android.app Service START_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 ), then leave it in the started state but don't retain this delivered intent.

Usage

From source file:edu.berkeley.eecs.cfc_tracker.test.location.SendMockLocationService.java

public int onStartCommand(Context ctxt, Intent startIntent, int flags, int startId) {
    mCachedContext = ctxt;/*from   w  ww.j a v  a 2  s  .c  o  m*/
    // Get the type of test to run
    mTestRequest = startIntent.getAction();

    /*
     * If the incoming Intent was a request to run a one-time or continuous test
     */
    if ((TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_ONCE))
            || (TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_CONTINUOUS))) {

        // Get the pause interval and injection interval
        mPauseInterval = startIntent.getIntExtra(LocationUtils.EXTRA_PAUSE_VALUE, 2);
        mInjectionInterval = startIntent.getIntExtra(LocationUtils.EXTRA_SEND_INTERVAL, 1);

        // Start connecting to Location Services
        mGoogleApiClient.connect();
    } else if (TextUtils.equals(mTestRequest, LocationUtils.ACTION_STOP_TEST)) {

        // Send a message back to the main activity that the test is stopping
        sendBroadcastMessage(LocationUtils.CODE_TEST_STOPPED, 0);

        // Stop this Service
        stopSelf();
    }

    /*
     * Tell the system to keep the Service alive, but to discard the Intent that
     * started the Service
     */
    return Service.START_STICKY;
}

From source file:com.appsimobile.appsii.Appsi.java

@Override
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand() called with: " + "intent = [" + intent + "], flags = [" + flags
            + "], startId = [" + startId + "]");
    startAppsiService();/*from  ww  w . jav a  2  s  .co  m*/
    // force initialize the home config to make everything a bit smoother
    // and this makes sure we don't have to wait for it when opening the
    // sidebar for the first time.
    // mHomeItemConfigurationHelper

    String action = intent == null ? null : intent.getAction();
    if (ACTION_TRY_PAGE.equals(action)) {

        HotspotPageEntry entry = intent.getParcelableExtra("entry");
        HotspotItem hotspotItem = intent.getParcelableExtra("hotspot");
        if (entry != null && hotspotItem != null) {
            CircularArray<HotspotPageEntry> entries = new CircularArray<>(1);
            entries.addFirst(entry);
            openSidebar(hotspotItem, entries, 0, true);
        }
    }

    return Service.START_STICKY;
}

From source file:com.paywith.ibeacon.service.IBeaconService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("Service", "onStartCommand");
    return android.app.Service.START_STICKY;
}

From source file:com.dellingertech.andevcon.mocklocationprovider.SendMockLocationService.java

@Override
public int onStartCommand(Intent startIntent, int flags, int startId) {
    // Get the type of test to run
    mTestRequest = startIntent.getAction();

    /*//from w w  w .  ja v a 2s .c  o  m
     * If the incoming Intent was a request to run a one-time or continuous test
     */
    if ((TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_ONCE))
            || (TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_CONTINUOUS))) {

        // Get the pause interval and injection interval
        mPauseInterval = startIntent.getIntExtra(LocationUtils.EXTRA_PAUSE_VALUE, 2);
        mInjectionInterval = startIntent.getIntExtra(LocationUtils.EXTRA_SEND_INTERVAL, 1);

        // Post a notification in the notification bar that a test is starting
        postNotification(getString(R.string.notification_content_test_start));

        // Create a location client
        mLocationClient = new LocationClient(this, this, this);

        // Start connecting to Location Services
        mLocationClient.connect();

    } else if (TextUtils.equals(mTestRequest, LocationUtils.ACTION_STOP_TEST)) {

        // Remove any existing notifications
        removeNotification();

        // Send a message back to the main activity that the test is stopping
        sendBroadcastMessage(LocationUtils.CODE_TEST_STOPPED, 0);

        // Stop this Service
        stopSelf();
    }

    /*
     * Tell the system to keep the Service alive, but to discard the Intent that
     * started the Service
     */
    return Service.START_STICKY;
}

From source file:com.github.stkent.landmarkedlocationprovider.SendMockLocationService.java

@Override
public int onStartCommand(Intent startIntent, int flags, int startId) {
    // Get the type of test to run
    mTestRequest = startIntent.getAction();

    /*/* w  ww  .j a v a  2 s.  com*/
     * If the incoming Intent was a request to run a one-time or continuous test
     */
    if ((TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_ONCE))
            || (TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_CONTINUOUS))) {

        // Get the pause interval and injection interval
        mPauseInterval = startIntent.getIntExtra(LocationUtils.EXTRA_PAUSE_VALUE, 2);
        mInjectionInterval = startIntent.getIntExtra(LocationUtils.EXTRA_SEND_INTERVAL, 1);

        // Post a notification in the notification bar that a test is starting
        postNotification(getString(R.string.notification_content_test_start));

        googleApiClient = new GoogleApiClient.Builder(this.getApplicationContext()).addApi(LocationServices.API)
                .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

        googleApiClient.connect();

    } else if (TextUtils.equals(mTestRequest, LocationUtils.ACTION_STOP_TEST)) {

        // Remove any existing notifications
        removeNotification();

        // Send a message back to the main activity that the test is stopping
        sendBroadcastMessage(LocationUtils.CODE_TEST_STOPPED, 0);

        // Stop this Service
        stopSelf();
    }

    /*
     * Tell the system to keep the Service alive, but to discard the Intent that
     * started the Service
     */
    return Service.START_STICKY;
}

From source file:com.bonsai.btcreceive.WalletService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    WalletApplication wallapp = (WalletApplication) getApplicationContext();

    // Establish our SyncState
    Bundle bundle = intent.getExtras();/*from   w  w w  .  j  a v a2s  .c  o m*/
    String syncStateStr = bundle.getString("SyncState");
    if (syncStateStr == null)
        syncStateStr = "STARTUP";
    mSyncState = syncStateStr.equals("CREATED") ? SyncState.CREATED
            : syncStateStr.equals("RESTORE") ? SyncState.RESTORE
                    : syncStateStr.equals("STARTUP") ? SyncState.STARTUP
                            : syncStateStr.equals("RESCAN") ? SyncState.RESCAN
                                    : syncStateStr.equals("RERESCAN") ? SyncState.RERESCAN : SyncState.STARTUP;

    mKeyCrypter = wallapp.mKeyCrypter;
    mAesKey = wallapp.mAesKey;

    // Set any new key's creation time to now.
    long now = Utils.now().getTime() / 1000;

    mTask = new SetupWalletTask();
    mTask.execute(now);

    mLogger.info("WalletService started");

    showStatusNotification();

    mIsRunning = true;

    return Service.START_STICKY;
}

From source file:com.halseyburgund.rwframework.core.RWService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // intent will be null on restart!
    if (intent != null) {
        getSettingsFromIntent(intent);// w w w  .  j  ava2  s. com
    }

    // create a pending intent to start the specified activity from the notification
    Intent ovIntent = new Intent(this, mNotificationActivity);
    mNotificationPendingIntent = PendingIntent.getActivity(this, 0, ovIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

    // create a notification and move service to foreground
    mRwNotification = new Notification(mNotificationIconId, "Roundware Service Started",
            System.currentTimeMillis());
    mRwNotification.number = 1;
    mRwNotification.flags = mRwNotification.flags | Notification.FLAG_FOREGROUND_SERVICE
            | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    setNotificationText("");

    startForeground(NOTIFICATION_ID, mRwNotification);

    // try to go on-line, this will attempt to get the configuration and tags
    manageSessionState(SessionState.ON_LINE);

    return Service.START_STICKY;
}

From source file:com.bonsai.wallet32.WalletService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // Establish our SyncState
    mSyncState = SyncState.STARTUP;//from w  ww .j  av  a 2  s .c o  m
    if (intent != null) {
        Bundle bundle = intent.getExtras();
        String syncStateStr = bundle.getString("SyncState");
        if (syncStateStr != null)
            mSyncState = syncStateStr.equals("CREATED") ? SyncState.CREATED
                    : syncStateStr.equals("RESTORE") ? SyncState.RESTORE
                            : syncStateStr.equals("STARTUP") ? SyncState.STARTUP
                                    : syncStateStr.equals("RESCAN") ? SyncState.RESCAN
                                            : syncStateStr.equals("RERESCAN") ? SyncState.RERESCAN
                                                    : SyncState.STARTUP;
    }

    mKeyCrypter = mApp.mKeyCrypter;
    mAesKey = mApp.mAesKey;

    // Set any new key's creation time to now.
    long now = Utils.now().getTime() / 1000;

    mTask = new SetupWalletTask();
    mTask.execute(now);

    mLogger.info("WalletService started");

    showStatusNotification();

    mIsRunning = true;

    return Service.START_STICKY;
}

From source file:com.nbplus.iotapp.service.IoTService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand in service ...");
    /**// ww w .j a v a 2  s .  com
     * ? ??? .
     */
    return Service.START_STICKY;//super.onStartCommand(intent, flags, startId);
}

From source file:com.mwebster.exchange.SyncManager.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    alwaysLog("!!! EAS SyncManager, onStartCommand");

    // Restore accounts, if it has not happened already
    AccountBackupRestore.restoreAccountsIfNeeded(this);

    maybeStartSyncManagerThread();//from ww w.j  a  va  2  s.c  om
    if (sServiceThread == null) {
        alwaysLog("!!! EAS SyncManager, stopping self");
        stopSelf();
    }
    return Service.START_STICKY;
}