我有一个BroadcastReceiver,它在传递参数时接收Google Cloud Messaging(GCM)的JSON,根据该参数,服务正在开始该类的全局对象,服务每隔一段时间就将该单元的位置发送到服务器,然后在同一个GCM上向他发送了另一条消息来阻止他,问题是当我停止服务时说这项服务是NULL,但仍然发送该位置.我想停止服务停止发送位置.
BroadcastReceiver
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
String TAG = "MainActivity";
ServicioGPS service1;
int nroService;
@Override
public void onReceive(Context context, Intent intent) {
// == I get the JSON
Bundle extras= intent.getExtras();
// == I check if I want to start the service
if (extras.containsKey("Position")) {
service1 = new ServiceGPS(context);
nroService= service1.onStartCommand(intent, 0, 58);
Log.i(TAG, String.valueOf(nroService));
}
else
{
// == I check if I want to stop the service
if (extras.containsKey("stop")) {
// == Exist error …Run Code Online (Sandbox Code Playgroud)