android.content.Context#stopService ( )源码实例Demo

下面列出了android.content.Context#stopService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: letv   文件: JiGuangReceiver.java
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    if (TextUtils.equals(intent.getAction(), JPushInterface.ACTION_MESSAGE_RECEIVED)) {
        String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
        if (!TextUtils.isEmpty(message)) {
            try {
                if (!JSONObject.NULL.equals(new JSONObject(message))) {
                    context.stopService(new Intent(context, LetvPushService.class));
                    Intent serviceIntent = new Intent(context, LetvPushService.class);
                    serviceIntent.putExtra(JPushInterface.EXTRA_MESSAGE, message);
                    context.startService(serviceIntent);
                    if (!TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_MSG_ID))) {
                        JPushInterface.reportNotificationOpened(context, bundle.getString(JPushInterface.EXTRA_MSG_ID));
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: ServiceLifecycleTest.java
@Test
public void testBindStartStopUnbind() throws InterruptedException {
    Context context = InstrumentationRegistry.getTargetContext();
    ServiceConnection connection = bindToService();
    awaitAndAssertEvents(ON_CREATE, ON_START);

    context.startService(mServiceIntent);
    // Precaution: give a chance to dispatch events
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    // still the same events
    awaitAndAssertEvents(ON_CREATE, ON_START);

    context.stopService(mServiceIntent);
    // Precaution: give a chance to dispatch events
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    // service is still bound
    awaitAndAssertEvents(ON_CREATE, ON_START);

    context.unbindService(connection);
    awaitAndAssertEvents(ON_CREATE, ON_START,
            ON_STOP, ON_DESTROY);
}
 
/**
 * 停止某个插件Service, 当全部的插件Service都停止之后, ProxyService也会停止
 * @param targetIntent
 * @return
 */
public int stopService(Intent targetIntent) {
    ServiceInfo serviceInfo = selectPluginService(targetIntent);
    if (serviceInfo == null) {
        Log.w(TAG, "can not found service: " + targetIntent.getComponent());
        return 0;
    }
    Service service = mServiceMap.get(serviceInfo.name);
    if (service == null) {
        Log.w(TAG, "can not runnning, are you stopped it multi-times?");
        return 0;
    }
    service.onDestroy();
    mServiceMap.remove(serviceInfo.name);
    if (mServiceMap.isEmpty()) {
        // 没有Service了, 这个没有必要存在了
        Log.d(TAG, "service all stopped, stop proxy");
        Context appContext = UPFApplication.getContext();
        appContext.stopService(new Intent().setComponent(new ComponentName(appContext.getPackageName(), ProxyService.class.getName())));
    }
    return 1;
}
 
源代码4 项目: linphone-android   文件: BootReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SHUTDOWN)) {
        android.util.Log.d(
                "Linphone",
                "[Boot Receiver] Device is shutting down, destroying Core to unregister");
        context.stopService(
                new Intent(Intent.ACTION_MAIN).setClass(context, LinphoneService.class));
    } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
        LinphonePreferences.instance().setContext(context);
        boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
        android.util.Log.i(
                "Linphone", "[Boot Receiver] Device is starting, auto_start is " + autostart);

        if (autostart && !LinphoneService.isReady()) {
            startService(context);
        }
    } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_MY_PACKAGE_REPLACED)) {
        LinphonePreferences.instance().setContext(context);
        boolean foregroundService =
                LinphonePreferences.instance().getServiceNotificationVisibility();
        android.util.Log.i(
                "Linphone",
                "[Boot Receiver] App has been updated, foreground service is "
                        + foregroundService);

        if (foregroundService && !LinphoneService.isReady()) {
            startService(context);
        }
    }
}
 
源代码5 项目: PhoneProfilesPlus   文件: PhoneStateScanner.java
static void stopAutoRegistration(Context context, boolean clearRegistration) {
    //PPApplication.logE("PhoneStateScanner.stopAutoRegistration", "xxx");

    // stop registration service
    context.stopService(new Intent(context.getApplicationContext(), MobileCellsRegistrationService.class));
    //MobileCellsRegistrationService.stop(context);

    if (clearRegistration) {
        //clearEventList();
        // set enabledAutoRegistration=false
        //PPApplication.logE("[REG] PhoneStateScanner.stopAutoRegistration", "setMobileCellsAutoRegistration(true)");
        MobileCellsRegistrationService.setMobileCellsAutoRegistration(context, true);
    }
}
 
源代码6 项目: Float-Bar   文件: HomeKeyReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
		String reason = intent.getStringExtra(SYSTEM_REASON);
		if (reason != null) {
			if (reason.equals(SYSTEM_HOME_KEY)) {
				Log.e("homekey", "home键被点击");
				context.stopService(new Intent(context, DrawService.class));
			} else if (reason.equals(SYSTEM_RECENT_APPS)) {
				Log.e("homekey", "长按home键");
			}
		}
	}
}
 
源代码7 项目: AndroidComponentPlugin   文件: ServiceManager20.java
/**
 * 停止某个插件Service, 当全部的插件Service都停止之后, ProxyService也会停止
 *
 * @param targetIntent targetIntent
 * @return int
 */
public int stopService(Intent targetIntent) {
    ServiceInfo serviceInfo = selectPluginService(targetIntent);
    if (serviceInfo == null) {
        Log.w(TAG, "can not found service: " + targetIntent.getComponent());
        return 0;
    }
    String processName3 = ProcessUtil.getProcessNameViaManager(MApplication.getInstance());
    Log.d(TAG, "3processName:" + processName3);
    Log.d(TAG, "3mServiceMap.size:" + mServiceMap.size());
    Log.d(TAG, "3mServiceMap.get(serviceInfo.name):" + serviceInfo.name);

    Service service = mServiceMap.get(serviceInfo.name);
    if (service == null) {
        Log.w(TAG, "can not runnning, are you stopped it multi-times?");
        return 0;
    }
    service.onDestroy();
    mServiceMap.remove(serviceInfo.name);
    if (mServiceMap.isEmpty()) {
        // 没有Service了, 这个没有必要存在了
        Log.d(TAG, "service all stopped, stop proxy");
        Context appContext = MApplication.getInstance();
        appContext.stopService(new Intent().setComponent(new ComponentName(appContext.getPackageName(), PluginProxyService.class.getName())));
    }
    return 1;
}
 
源代码8 项目: letv   文件: DialogService.java
public static void closePipView(Context context) {
    if (context != null) {
        Intent serviceStop = new Intent();
        serviceStop.setClass(context, DialogService.class);
        context.stopService(serviceStop);
    }
}
 
源代码9 项目: java-n-IDE-for-Android   文件: ServiceHelper.java
public static void startOrStopCrazyLogger(Context context) {

        boolean alreadyRunning = checkIfServiceIsRunning(context, CrazyLoggerService.class);
        Intent intent = new Intent(context, CrazyLoggerService.class);

        if (!alreadyRunning) {
            context.startService(intent);
        } else {
            context.stopService(intent);
        }

    }
 
源代码10 项目: matlog   文件: ServiceHelper.java
public static synchronized void stopBackgroundServiceIfRunning(Context context) {
    boolean alreadyRunning = ServiceHelper.checkIfServiceIsRunning(context, LogcatRecordingService.class);

    log.d("Is CatlogService running: %s", alreadyRunning);

    if (alreadyRunning) {
        Intent intent = new Intent(context, LogcatRecordingService.class);
        context.stopService(intent);
    }

}
 
源代码11 项目: physical-web   文件: ScreenListenerService.java
@Override
public void onReceive(Context context, Intent intent) {
  Intent discoveryIntent = new Intent(context, UrlDeviceDiscoveryService.class);
  if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
    context.startService(discoveryIntent);
  } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
    context.stopService(discoveryIntent);
  }
}
 
源代码12 项目: SimplePomodoro-android   文件: MyUtils.java
public static void autoStopWakelockService(Context c){
	if(isWakeLockServiceRunning()){
		c.stopService(new Intent(c, WakeLockService.class));
	}
}
 
源代码13 项目: BalloonPerformer   文件: ReleaseService.java
public static void stopService(Context context) {
    Intent intent = new Intent(context, ReleaseService.class);
    context.stopService(intent);
    // 用户想要关闭悬浮窗
    PreferenceHelper.setIsRunning(context, false);
}
 
源代码14 项目: rcloneExplorer   文件: UploadCancelAction.java
@Override
public void onReceive(Context context, Intent intent) {
    Intent uploadIntent = new Intent(context, UploadService.class);
    context.stopService(uploadIntent);
}
 
源代码15 项目: rcloneExplorer   文件: SyncCancelAction.java
@Override
public void onReceive(Context context, Intent intent) {
    Intent syncIntent = new Intent(context, SyncService.class);
    context.stopService(syncIntent);
}
 
源代码16 项目: Android   文件: SocketService.java
public static void stopServer(Context context) {
    Intent intent = new Intent(context, SocketService.class);
    context.stopService(intent);
}
 
源代码17 项目: LivePlayback   文件: MediaPlayerService.java
public static void intentToStop(Context context) {
    context.stopService(newIntent(context));
}
 
源代码18 项目: Daedalus   文件: Daedalus.java
public static void deactivateService(Context context) {
    context.startService(getServiceIntent(context).setAction(DaedalusVpnService.ACTION_DEACTIVATE));
    context.stopService(getServiceIntent(context));
}
 
源代码19 项目: mangosta-android   文件: XMPPSession.java
public static void stopService(Context context) {
    Intent serviceIntent = new Intent(context, XMPPSessionService.class);
    serviceIntent.setPackage("com.nanoscopia.services");
    context.stopService(serviceIntent);
}
 
源代码20 项目: AndroidProgramming3e   文件: ShutdownReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
    Intent shutdown = new Intent(context, MockWalkerService.class);
    context.stopService(shutdown);
}
 
 方法所在类
 同类方法