Android IntentService не запускается

Я знаю, что этот вопрос задавался много раз, но все остальные темы нея не могу решить мою проблемуЯ не вижу ничего плохого в моем коде. Может быть, я что-то здесь упустил, кто-нибудь может мне помочь?

Код для Службы намерений:

package Services;

import android.app.IntentService;
import android.content.Intent;
import android.widget.Toast;

public class WifiSearchService extends IntentService {

  /** 
   * A constructor is required, and must call the super IntentService(String)
   * constructor with a name for the worker thread.
   */
  public WifiSearchService() {
      super("WifiSearchService");
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
      return super.onStartCommand(intent,flags,startId);
  }

  /**
   * The IntentService calls this method from the default worker thread with
   * the intent that started the service. When this method returns, IntentService
   * stops the service, as appropriate.
   */
  @Override
  protected void onHandleIntent(Intent intent) {
      // Normally we would do some work here, like download a file.
  // For our sample, we just sleep for 5 seconds.
      long endTime = System.currentTimeMillis() + 5*1000;
      while (System.currentTimeMillis() < endTime) {
          synchronized (this) {
              try {
                  wait(endTime - System.currentTimeMillis());
              } catch (Exception e) {
              }
          }
      }
  }

}

Запуск службы нажатием переключателя:

package com.cdobiz.wifimapper;

import Services.WifiSearchService;
import android.os.Bundle;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;

public class MainActivity extends Activity {

    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        context = this;

        setContentView(R.layout.activity_main);


        Switch serviceSwitch = (Switch) this.findViewById(R.id.switchService);

        serviceSwitch.setChecked(isMyServiceRunning());

        serviceSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(){

            @Override
            public void onCheckedChanged(CompoundButton view, boolean state) {

                if(state){
                    startService(new Intent(context, WifiSearchService.class));
                }else{
                    stopService(new Intent(context, WifiSearchService.class));
                }
            }

        });

    }

    private boolean isMyServiceRunning() {
        ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            Log.v("debug", service.service.getClassName());
            if ("com.cdobiz.wifimapper.services.WifiSearchService".equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

Manifest:




    
    

    
        
            
                

                
            
        
        
    


Ответы на вопрос(5)

Ваш ответ на вопрос