android 从activity中停止Service

来源:互联网 发布:java 高并发高可用 编辑:程序博客网 时间:2024/05/16 07:27

1,在AndroidManifest.xml注册Service

        <service android:name=".service.SensorService" >
            <intent-filter>
                <action android:name="ITOP.MOBILE.SIMPLE.SERVICE.SENSORSERVICE"/>
            </intent-filter>
        </service>

2,在Activity中调用

                final Intent intent = new Intent();
                intent.setAction("ITOP.MOBILE.SIMPLE.SERVICE.SENSORSERVICE");
                stopService(intent);