Example usage for android.content Context startService

List of usage examples for android.content Context startService

Introduction

In this page you can find the example usage for android.content Context startService.

Prototype

@Nullable
public abstract ComponentName startService(Intent service);

Source Link

Document

Request that a given application service be started.

Usage

From source file:com.achep.acdisplay.services.BathService.java

public static void startService(Context context, Class<? extends ChildService> clazz) {
    synchronized (monitor) {
        if (sCreated) {

            // Send broadcast intent to notify BathService
            // to start this child.
            Intent intent = new Intent(ACTION_ADD_SERVICE);
            intent.putExtra(EXTRA_SERVICE_CLASS, clazz);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
        } else if (!sServiceMap.containsKey(clazz)) {
            try {
                // Put empty child to host service and start host.
                sServiceMap.put(clazz, clazz.newInstance());
                context.startService(new Intent(context, BathService.class));
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException(e.getMessage()); // Should never happen
            }//  w  ww  .j a v a  2s .com
        }
    }
}

From source file:de.schildbach.wallet.service.BlockchainService.java

public static void resetBlockchain(final Context context) {
    // implicitly stops blockchain service
    context.startService(
            new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, context, BlockchainService.class));
}

From source file:com.bullmobi.message.services.BathService.java

public static void startService(Context context, Class<? extends ChildService> clazz) {
    synchronized (monitor) {
        if (sCreated) {

            // Send broadcast intent to notify BathService
            // to start this child.
            Intent intent = new Intent(ACTION_ADD_SERVICE);
            intent.putExtra(EXTRA_SERVICE_CLASS, clazz);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);

        } else if (!sServiceMap.containsKey(clazz)) {
            try {

                // Put empty child to host service and start host.
                sServiceMap.put(clazz, clazz.newInstance());
                context.startService(new Intent(context, BathService.class));
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException(e.getMessage()); // Should never happen
            }/*w  ww  .  j av a  2 s  .c om*/
        }
    }
}

From source file:syncthing.android.service.SyncthingUtils.java

/**
 * Used to build and show a notification when Syncthing is sent into the background
 *
 * @param context The {@link Context} to use.
 *///from ww w  .  j  a v  a  2 s  . com
public static void notifyForegroundStateChanged(final Context context, boolean inForeground) {
    int old = sForegroundActivities;
    if (inForeground) {
        sForegroundActivities++;
    } else {
        sForegroundActivities--;
    }

    if (old == 0 || sForegroundActivities == 0) {
        final Intent intent = new Intent(context, SyncthingInstance.class);
        intent.setAction(SyncthingInstance.FOREGROUND_STATE_CHANGED);
        intent.putExtra(SyncthingInstance.EXTRA_NOW_IN_FOREGROUND, sForegroundActivities != 0);
        context.startService(intent);
    }
}

From source file:de.schildbach.wallet.service.BlockchainService.java

public static void start(final Context context, final boolean cancelCoinsReceived) {
    if (cancelCoinsReceived)
        context.startService(new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED, null, context,
                BlockchainService.class));
    else//from ww  w .  j  ava2 s . co m
        context.startService(new Intent(context, BlockchainService.class));
}

From source file:org.kontalk.service.DownloadService.java

public static void start(Context context, long databaseId, String sender, String mime, long timestamp,
        boolean encrypted, String url, boolean notify) {
    Intent i = new Intent(context, DownloadService.class);
    i.setAction(DownloadService.ACTION_DOWNLOAD_URL);
    i.putExtra(CompositeMessage.MSG_ID, databaseId);
    i.putExtra(CompositeMessage.MSG_SENDER, sender);
    i.putExtra(CompositeMessage.MSG_MIME, mime);
    i.putExtra(CompositeMessage.MSG_TIMESTAMP, timestamp);
    i.putExtra(CompositeMessage.MSG_ENCRYPTED, encrypted);
    i.putExtra(EXTRA_NOTIFY, notify);/* w  w w  . ja v  a  2s . co m*/
    i.setData(Uri.parse(url));
    context.startService(i);
}

From source file:im.vector.activity.CommonActivityUtils.java

private static void sendEventStreamAction(Context context, EventStreamService.StreamAction action) {
    Context appContext = context.getApplicationContext();

    // kill active connections
    Intent killStreamService = new Intent(appContext, EventStreamService.class);
    killStreamService.putExtra(EventStreamService.EXTRA_STREAM_ACTION, action.ordinal());
    appContext.startService(killStreamService);
}

From source file:com.acrr.acdisplay.services.BathService.java

public static void startService(Context context, Class<? extends ChildService> clazz) {
    synchronized (monitor) {
        if (sRunning) {
            Intent intent = new Intent(ACTION_ADD_SERVICE);
            intent.putExtra(EXTRA_SERVICE_CLASS, clazz);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
        } else if (!sServiceMap.containsKey(clazz)) {
            ChildService instance;// w  ww . j a v a  2 s .c o m
            try {
                instance = clazz.newInstance();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

            sServiceMap.put(clazz, instance);
            if (!sCreated)
                context.startService(new Intent(context, BathService.class));
        }
    }
}

From source file:com.google.android.gm.ay.java

public static void bf(final Context context) {
    final b dd = b.DD();
    final String bs = dd.bs(context);
    final android.accounts.Account[] accountsByType = AccountManager.get(context)
            .getAccountsByType("com.google");
    if (accountsByType.length > 0 && !bi(context)) {
        final String name = accountsByType[0].name;
        final Intent intent = new Intent();
        intent.setClass(context, (Class) ao.class);
        intent.putExtra("account-name", name);
        context.startService(intent);
    }//  w  w  w .j av a  2  s  .  c  o m
    for (int length = accountsByType.length, i = 0; i < length; ++i) {
        if (accountsByType[i].name.equals(bs)) {
            return;
        }
    }
    if (accountsByType.length > 0) {
        dd.z(context, accountsByType[0].name);
    }
}

From source file:com.tonyodev.fetch.FetchService.java

public static void processPendingRequests(@NonNull Context context) {

    if (context == null) {
        throw new NullPointerException("Context cannot be null");
    }//  w w w .j a va2  s .c o  m

    Intent intent = new Intent(context, FetchService.class);
    intent.putExtra(FetchService.ACTION_TYPE, FetchService.ACTION_PROCESS_PENDING);
    context.startService(intent);
}