android.content.Context.stopService()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中android.content.Context.stopService()方法的一些代码示例,展示了Context.stopService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.stopService()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:stopService

Context.stopService介绍

暂无

代码示例

代码示例来源:origin: androidannotations/androidannotations

public boolean stop() {
    return context.stopService(intent);
  }
}

代码示例来源:origin: oasisfeng/condom

@Override public boolean stopService(Intent name) {
  return mBase.stopService(name);
}

代码示例来源:origin: lingochamp/FileDownloader

@Override
public void unbindByContext(Context context) {
  Intent i = new Intent(context, SERVICE_CLASS);
  context.stopService(i);
  handler = null;
}

代码示例来源:origin: MindorksOpenSource/android-mvp-architecture

public static void stop(Context context) {
  context.stopService(new Intent(context, SyncService.class));
}

代码示例来源:origin: gotev/android-upload-service

/**
 * Stops the service.
 * @param context application context
 * @param forceStop stops the service no matter if some tasks are running
 * @return true if the service is getting stopped, false otherwise
 */
public static synchronized boolean stop(final Context context, boolean forceStop) {
  if (forceStop) {
    return context.stopService(new Intent(context, UploadService.class));
  }
  return uploadTasksMap.isEmpty() && context.stopService(new Intent(context, UploadService.class));
}

代码示例来源:origin: joyoyao/superCleanMaster

/**
 * 停止服务.
 *
 * @param context   the context
 * @param className the class name
 * @return true, if successful
 */
public static boolean stopRunningService(Context context, String className) {
  Intent intent_service = null;
  boolean ret = false;
  try {
    intent_service = new Intent(context, Class.forName(className));
  } catch (Exception e) {
    e.printStackTrace();
  }
  if (intent_service != null) {
    ret = context.stopService(intent_service);
  }
  return ret;
}

代码示例来源:origin: stackoverflow.com

public class NetWatcher extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    //here, check that the network connection is available. If yes, start your service. If not, stop your service.
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null) {
      if (info.isConnected()) {
        //start service
        Intent intent = new Intent(context, MyService.class);
        context.startService(intent);
      }
      else {
        //stop service
        Intent intent = new Intent(context, MyService.class);
        context.stopService(intent);
      }
    }
  }
}

代码示例来源:origin: lingochamp/FileDownloader

@Override
public void unbindByContext(final Context context) {
  if (!bindContexts.contains(context)) {
    return;
  }
  if (FileDownloadLog.NEED_LOG) {
    FileDownloadLog.d(this, "unbindByContext %s", context);
  }
  bindContexts.remove(context);
  if (bindContexts.isEmpty()) {
    releaseConnect(false);
  }
  Intent i = new Intent(context, serviceClass);
  context.unbindService(this);
  context.stopService(i);
}

代码示例来源:origin: ACRA/acra

private void stopServices() {
  if (config.stopServicesOnCrash()) {
    try {
      final ActivityManager activityManager = SystemServices.getActivityManager(context);
      final List<ActivityManager.RunningServiceInfo> runningServices = activityManager.getRunningServices(Integer.MAX_VALUE);
      final int pid = Process.myPid();
      for (ActivityManager.RunningServiceInfo serviceInfo : runningServices) {
        if (serviceInfo.pid == pid && !LegacySenderService.class.getName().equals(serviceInfo.service.getClassName()) && !JobSenderService.class.getName().equals(serviceInfo.service.getClassName())) {
          try {
            final Intent intent = new Intent();
            intent.setComponent(serviceInfo.service);
            context.stopService(intent);
          } catch (SecurityException e) {
            if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Unable to stop Service " + serviceInfo.service.getClassName() + ". Permission denied");
          }
        }
      }
    } catch (SystemServices.ServiceNotReachedException e) {
      ACRA.log.e(LOG_TAG, "Unable to stop services", e);
    }
  }
}

代码示例来源:origin: oasisfeng/condom

runInSeparateProcess(new TestService.Procedure() { @Override public void run(final Context context) {
  final Intent intent = new Intent(context, TestService.class);
  assertNotNull("Test service is not properly setup.", context.startService(intent));
  assertTrue(context.stopService(intent));
  installCondomProcess(context, new CondomOptions().setOutboundJudge(sBlockAllJudge));
  withFakeSelfPackageName(new Runnable() { @Override public void run() {
    assertNull(context.startService(intent));
  }});    // Block by outbound judge
  assertTrue(context.stopService(intent));
}});
// TODO: More cases

代码示例来源:origin: AltBeacon/android-beacon-library

/**
   * Method reserved for system use
   */
  @Override
  public void unbindService(ServiceConnection conn) {
    application.getApplicationContext().unbindService(conn);
    application.getApplicationContext().stopService(serviceIntent);
    serviceConnected = false;
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

private synchronized void publishFinished(PublishBean bean) {
  publishQueue.poll();
  Logger.w("publishFinished" + publishQueue.size());
  // 队列发送完毕了,且当前运行的页面不是发布页面,就停止服务
  if (publishQueue.size() == 0)
    context.stopService(new Intent(context, PublishService.class));
  else {
    postDelayed(new Runnable() {
      
      @Override
      public void run() {
        onPublish(publishQueue.peek());
      }
      
    }, 2 * 1000);
  }
}

代码示例来源:origin: Trumeet/MiPushFramework

@Override public boolean stopService(Intent name) {
  return mBase.stopService(name);
}

代码示例来源:origin: ac-pm/Inspeckage

public void stopService() {
    context.stopService(new Intent(context, InspeckageService.class));
    context.stopService(new Intent(context, LogService.class));
  }
}

代码示例来源:origin: multidots/android-app-common-tasks

/**
 * stop background music
 *
 * @param mContext
 */
public static void backgroundMusicStop(Context mContext) {
  mContext.stopService(new Intent(mContext, BackgroundMusicService.class));
}

代码示例来源:origin: multidots/android-app-common-tasks

/**
 * stop background music
 *
 * @param mContext
 */
public static void backgroundMusicStop(Context mContext) {
  mContext.stopService(new Intent(mContext, BackgroundMusicService.class));
}

代码示例来源:origin: ac-pm/Inspeckage

public void stopService() {
    context.stopService(new Intent(context, InspeckageService.class));
    context.stopService(new Intent(context, LogService.class));
  }
}

代码示例来源:origin: ac-pm/Inspeckage

public void stopService() {
  context.stopService(new Intent(context, InspeckageService.class));
}

代码示例来源:origin: ac-pm/Inspeckage

private Response stopWS() {
  mContext.stopService(new Intent(mContext, LogService.class));
  return ok("OK");
}

代码示例来源:origin: iTXTech/Daedalus

public static void deactivateService(Context context) {
  context.startService(getServiceIntent(context).setAction(DaedalusVpnService.ACTION_DEACTIVATE));
  context.stopService(getServiceIntent(context));
}

相关文章

Context类方法