public ComponentName start() { return context.startService(intent); }
public class autostart extends BroadcastReceiver { public void onReceive(Context context, Intent arg1) { Intent intent = new Intent(context,service.class); context.startService(intent); Log.i("Autostart", "started"); } }
public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent myIntent = new Intent(context, YourService.class); context.startService(myIntent); } }
public class StartMyServiceAtBootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { Intent serviceIntent = new Intent(context, MyService.class); context.startService(serviceIntent); } } }
private void notifyService() throws Exception { Intent intent = getIntent(context, serviceClass, DownloadService.ACTION_INIT); try { context.startService(intent); } catch (IllegalStateException e) { /* startService will fail if the app is in the background and the service isn't running. */ throw new Exception(e); } } }
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class ServiceStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent("com.prac.test.MyPersistingService"); i.setClass(context, MyPersistingService.class); context.startService(i); } }
public class OnBoot extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Create Intent Intent serviceIntent = new Intent(context, YourCoolService.class); // Start service context.startService(serviceIntent); } }
public static void startActionUpvote(@NonNull Context context, long storyId) { final Intent intent = new Intent(context, UpvoteStoryService.class); intent.setAction(ACTION_UPVOTE); intent.putExtra(EXTRA_STORY_ID, storyId); context.startService(intent); }
public static void asyncNext(final Context context) { final Intent previous = new Intent(context, MusicService.class); previous.setAction(MusicService.NEXT_ACTION); context.startService(previous); }
public static void asyncNext(final Context context) { final Intent previous = new Intent(context, MediaService.class); previous.setAction(MediaService.NEXT_ACTION); context.startService(previous); }
public static void previous(final Context context, final boolean force) { final Intent previous = new Intent(context, MusicService.class); if (force) { previous.setAction(MusicService.PREVIOUS_FORCE_ACTION); } else { previous.setAction(MusicService.PREVIOUS_ACTION); } context.startService(previous); }
private void pushAction(Context context, String ACTION) { Log.e("widget","action = " + ACTION); Intent startIntent = new Intent(context,MediaService.class); startIntent.setAction(ACTION); context.startService(startIntent); } }
@Override public void onReceive(Context context, Intent intent) { Log.e(getClass().getSimpleName(), "HackReceiver onReceive()"); Intent wrapped=intent.getParcelableExtra(Intent.EXTRA_INTENT); context.startService(wrapped); } }
public static void loadDocument(Context ctxt, Uri document) { Intent i=new Intent(ctxt, DocumentStorageService.class) .setAction(Intent.ACTION_OPEN_DOCUMENT) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .setData(document); ctxt.startService(i); }
/** * Starts the service without adding a new action. If there are any not finished actions and the * requirements are met, the service resumes executing actions. Otherwise it stops immediately. * * @param context A {@link Context}. * @param clazz The concrete download service to be started. * @see #startForeground(Context, Class) */ public static void start(Context context, Class<? extends DownloadService> clazz) { context.startService(getIntent(context, clazz, ACTION_INIT)); }
/** * Calls {@link Context#startForegroundService(Intent)} if {@link #SDK_INT} is 26 or higher, or * {@link Context#startService(Intent)} otherwise. * * @param context The context to call. * @param intent The intent to pass to the called method. * @return The result of the called method. */ public static ComponentName startForegroundService(Context context, Intent intent) { if (Util.SDK_INT >= 26) { return context.startForegroundService(intent); } else { return context.startService(intent); } }
public void updateService(Bundle extras) { if(!MusicPlayer.isPlaybackServiceConnected())return; final Intent intent = new Intent(context, MusicService.class); intent.setAction(MusicService.UPDATE_PREFERENCES); intent.putExtras(extras); context.startService(intent); }
static void startMeUp(Context ctxt, boolean foreground, boolean importantish) { Intent i=new Intent(ctxt, DemoService.class) .putExtra(EXTRA_FOREGROUND, foreground) .putExtra(EXTRA_IMPORTANTISH, importantish); if (foreground && Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) { ctxt.startForegroundService(i); } else { ctxt.startService(i); } }
public static void set(Context context, Intent i, Integer wakeLockId) { // Intent i = new Intent(); i.setClass(context, RemoteControlService.class); i.setAction(RemoteControlService.SET_ACTION); addWakeLockId(context, i, wakeLockId, true); context.startService(i); }
public static void startup(Context context) { File flagFile = context.getFileStreamPath(Constants.NO_NOTIFICATION_FLAG); if (Build.VERSION.SDK_INT >= 25 && flagFile.exists()) { showNotification = false; } context.startService(new Intent(context, DaemonService.class)); if (VirtualCore.get().isServerProcess()) { // PrivilegeAppOptimizer.notifyBootFinish(); DaemonJobService.scheduleJob(context); } }