Java Code Examples for android.app.Activity#stopService()

The following examples show how to use android.app.Activity#stopService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    final MainActivity parent = (MainActivity) mContext;
    parent.setUpdateFragment(null);
    mContext = null;

    if (getActivity().isFinishing()) {
        final Activity activity = getActivity();
        final Intent service = new Intent(activity, UpdateService.class);
        activity.stopService(service);
    }

    if (mProgressDialog != null && mProgressDialog.isShowing()) {
        mProgressDialog.dismiss();
    }
    if (mConnectionProgressDialog != null && mConnectionProgressDialog.isShowing()) {
        mConnectionProgressDialog.dismiss();
    }

    unbindImageViews();
    if(mMaxActiveSlotsAdapter != null) {
        mMaxActiveSlotsAdapter.clear();
        mMaxActiveSlotsAdapter = null;
    }
}
 
Example 2
Source File: AndroidWearPlugin.java    From cordova-androidwear with Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
	Log.d(TAG, "onDestroy");

	try {
		Activity context = cordova.getActivity();

		if (api != null)
			api.removeListener(messageListener);

		context.unbindService(serviceConnection);
		context.stopService(serviceIntent);
	} catch (Throwable t) {
		// catch any issues, typical for destroy routines
		// even if we failed to destroy something, we need to continue
		// destroying
		Log.w(TAG, "Failed to unbind from the service", t);
	}

	super.onDestroy();
}
 
Example 3
Source File: SensonListener.java    From LLApp with Apache License 2.0 5 votes vote down vote up
public void stopService(Activity activity){
    //暂停服务
    Intent intent = new Intent(activity, AidlService.class);
    activity.stopService(intent);

    //断开与远程Service的连接
    activity.unbindService(sc);
}
 
Example 4
Source File: BackgroundLocationServicesPlugin.java    From cordova-background-geolocation-services with Apache License 2.0 5 votes vote down vote up
/**
 * Override method in CordovaPlugin.
 * Checks to see if it should turn off
 */
public void onDestroy() {
    Activity activity = this.cordova.getActivity();

    if(isEnabled) {
        activity.stopService(updateServiceIntent);
        unbindServiceFromWebview(activity, updateServiceIntent);
    }
}
 
Example 5
Source File: UpdateFragment.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onDestroy() {
	super.onDestroy();

	if (getActivity().isFinishing()) {
		final Activity activity = getActivity();
		final Intent service = new Intent(activity, UpdateService.class);
		activity.stopService(service);
	}
}
 
Example 6
Source File: BackgroundMode.java    From cordova-plugin-background-mode with Apache License 2.0 5 votes vote down vote up
/**
 * Bind the activity to a background service and put them into foreground
 * state.
 */
private void stopService()
{
    Activity context = cordova.getActivity();
    Intent intent    = new Intent(context, ForegroundService.class);

    if (!isBind) return;

    fireEvent(Event.DEACTIVATE, null);
    context.unbindService(connection);
    context.stopService(intent);

    isBind = false;
}
 
Example 7
Source File: UpdateFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void cancelUnlockBeacon() {
    final Activity activity = getActivity();
    final Intent service = new Intent(activity, UpdateService.class);
    activity.stopService(service);
}
 
Example 8
Source File: BackgroundLocationServicesPlugin.java    From cordova-background-geolocation-services with Apache License 2.0 4 votes vote down vote up
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

        Activity activity = this.cordova.getActivity();

        Boolean result = false;
        updateServiceIntent = new Intent(activity, BackgroundLocationUpdateService.class);

        if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
              result = true;

              updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
              updateServiceIntent.putExtra("distanceFilter", distanceFilter);
              updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
              updateServiceIntent.putExtra("isDebugging", isDebugging);
              updateServiceIntent.putExtra("notificationTitle", notificationTitle);
              updateServiceIntent.putExtra("notificationText", notificationText);
              updateServiceIntent.putExtra("interval", interval);
              updateServiceIntent.putExtra("fastestInterval", fastestInterval);
              updateServiceIntent.putExtra("aggressiveInterval", aggressiveInterval);
              updateServiceIntent.putExtra("activitiesInterval", activitiesInterval);
              updateServiceIntent.putExtra("useActivityDetection", useActivityDetection);

            if (hasPermisssion()) {
                isServiceBound = bindServiceToWebview(activity, updateServiceIntent);
                isEnabled = true;
                callbackContext.success();
            } else {
                startCallback = callbackContext;
                PermissionHelper.requestPermissions(this, START_REQ_CODE, permissions);
            }

        } else if (ACTION_STOP.equalsIgnoreCase(action)) {
            isEnabled = false;
            result = true;
            activity.stopService(updateServiceIntent);
            callbackContext.success();

            result = unbindServiceFromWebview(activity, updateServiceIntent);

            if(result) {
                callbackContext.success();
            } else {
                callbackContext.error("Failed To Stop The Service");
            }
        } else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
            result = true;
            try {
                // [distanceFilter, desiredAccuracy, interval, fastestInterval, aggressiveInterval, debug, notificationTitle, notificationText, activityType, fences, url, params, headers]
                //  0               1                2         3                4                   5      6                   7                8              9
                this.distanceFilter = data.getString(0);
                this.desiredAccuracy = data.getString(1);
                this.interval = data.getString(2);
                this.fastestInterval = data.getString(3);
                this.aggressiveInterval = data.getString(4);
                this.isDebugging = data.getString(5);
                this.notificationTitle = data.getString(6);
                this.notificationText = data.getString(7);
                //this.activityType = data.getString(8);
                this.useActivityDetection = data.getString(9);
                this.activitiesInterval = data.getString(10);



            } catch (JSONException e) {
                Log.d(TAG, "Json Exception" + e);
                callbackContext.error("JSON Exception" + e.getMessage());
            }
        } else if (ACTION_SET_CONFIG.equalsIgnoreCase(action)) {
            result = true;
            // TODO reconfigure Service
            callbackContext.success();
        } else if(ACTION_GET_VERSION.equalsIgnoreCase(action)) {
            result = true;
            callbackContext.success(PLUGIN_VERSION);
        } else if(ACTION_REGISTER_FOR_LOCATION_UPDATES.equalsIgnoreCase(action)) {
            result = true;
            //Register the function for repeated location update
            locationUpdateCallback = callbackContext;
        } else if(ACTION_REGISTER_FOR_ACTIVITY_UPDATES.equalsIgnoreCase(action)) {
          result = true;
          detectedActivitiesCallback = callbackContext;
        } else if(ACTION_AGGRESSIVE_TRACKING.equalsIgnoreCase(action)) {
            result = true;
            if(isEnabled) {
                this.cordova.getActivity().sendBroadcast(new Intent(Constants.CHANGE_AGGRESSIVE));
                callbackContext.success();
            } else {
                callbackContext.error("Tracking not enabled, need to start tracking before starting aggressive tracking");
            }
        }

        return result;
    }
 
Example 9
Source File: UpdateFragment.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
	final Activity activity = getActivity();
	if (activity == null || !isResumed())
		return;

	final String action = intent.getAction();

	if (UpdateService.ACTION_STATE_CHANGED.equals(action)) {
		final int state = intent.getIntExtra(UpdateService.EXTRA_DATA, UpdateService.STATE_DISCONNECTED);

		switch (state) {
		case UpdateService.STATE_DISCONNECTED:
			mConnectButton.setText(R.string.action_connect);
			mConnectButton.setEnabled(true);
			setUuidControlsEnabled(false);
			setMajorMinorControlsEnabled(false);
			setRssiControlsEnabled(false);
			setManufacturerIdControlsEnabled(false);
			setAdvIntervalControlsEnabled(false);
			setLedControlsEnabled(false);
			mAdvancedTitleView.setEnabled(true);

			final Intent service = new Intent(activity, UpdateService.class);
			activity.unbindService(mServiceConnection);
			activity.stopService(service);
			mBinder = null;
			mBinded = false;
			break;
		case UpdateService.STATE_CONNECTED:
			mConnectButton.setText(R.string.action_disconnect);
			mConnectButton.setEnabled(true);
			break;
		case UpdateService.STATE_DISCONNECTING:
		case UpdateService.STATE_CONNECTING:
			mConnectButton.setEnabled(false);
			break;
		}
	} else if (UpdateService.ACTION_UUID_READY.equals(action)) {
		final UUID uuid = ((ParcelUuid) intent.getParcelableExtra(UpdateService.EXTRA_DATA)).getUuid();
		mUuidView.setText(uuid.toString());
		setUuidControlsEnabled(true);
	} else if (UpdateService.ACTION_MAJOR_MINOR_READY.equals(action)) {
		final int major = intent.getIntExtra(UpdateService.EXTRA_MAJOR, 0);
		final int minor = intent.getIntExtra(UpdateService.EXTRA_MINOR, 0);
		mMajorView.setText(String.valueOf(major));
		mMinorView.setText(String.valueOf(minor));
		setMajorMinorControlsEnabled(true);
	} else if (UpdateService.ACTION_RSSI_READY.equals(action)) {
		final int rssi = intent.getIntExtra(UpdateService.EXTRA_DATA, 0);
		mCalibratedRssiView.setTag(rssi);
		mCalibratedRssiView.setText(String.valueOf(rssi));
		setRssiControlsEnabled(true);
	} else if (UpdateService.ACTION_MANUFACTURER_ID_READY.equals(action)) {
		final int manufacturerId = intent.getIntExtra(UpdateService.EXTRA_DATA, 0);
		mManufacturerIdView.setText(String.valueOf(manufacturerId));
		setManufacturerIdControlsEnabled(true);
	} else if (UpdateService.ACTION_ADV_INTERVAL_READY.equals(action)) {
		final int interval = intent.getIntExtra(UpdateService.EXTRA_DATA, 0);
		mAdvIntervalView.setText(String.valueOf(interval));
		setAdvIntervalControlsEnabled(true);
	} else if (UpdateService.ACTION_LED_STATUS_READY.equals(action)) {
		final boolean on = intent.getBooleanExtra(UpdateService.EXTRA_DATA, false);
		mLedSwitchActionDisabled = true;
		mLedsSwitch.setChecked(on);
		mLedSwitchActionDisabled = false;
		setLedControlsEnabled(true);
	} else if (UpdateService.ACTION_DONE.equals(action)) {
		final boolean advanced = intent.getBooleanExtra(UpdateService.EXTRA_DATA, false);
		mAdvancedTitleView.setEnabled(advanced);
		mBinder.read();
	} else if (UpdateService.ACTION_GATT_ERROR.equals(action)) {
		final int error = intent.getIntExtra(UpdateService.EXTRA_DATA, 0);

		switch (error) {
		case UpdateService.ERROR_UNSUPPORTED_DEVICE:
			Toast.makeText(activity, R.string.update_error_device_not_supported, Toast.LENGTH_SHORT).show();
			break;
		default:
			Toast.makeText(activity, getString(R.string.update_error_other, error), Toast.LENGTH_SHORT).show();
			break;
		}
		mBinder.disconnectAndClose();
	}
}
 
Example 10
Source File: ActivityOverider.java    From AndroidPlugin with MIT License 4 votes vote down vote up
public static boolean overrideStopService(Activity fromAct,
        String pluginId, Intent intent) {
    // TODO overrideStopService
    Log.d(tag, "overrideStopService");
    return fromAct.stopService(intent);
}
 
Example 11
Source File: GpsServiceUtilities.java    From geopaparazzi with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Stop the service.
 *
 * @param activity the activity to use.
 */
public static void stopGpsService(Activity activity) {
    Intent intent = new Intent(activity, GpsService.class);
    activity.stopService(intent);
}