7

I am trying out Intent services. This is what I use to call it

    Button updateLocation = (Button) findViewById(R.id.btnUpdateLocation);
        updateLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent updateLocIntent=new Intent(ImTracking.this,UpdateLocation.class);
                startService(updateLocIntent);}});

However in my UpdateLocation class, it never hits any of my break points.

    public class UpdateLocation extends IntentService{

    public UpdateLocation() {
        super("UpdateLocation");
    }


    @Override
    protected void onHandleIntent(Intent intent) {

                SharedPreferences prefs = getSharedPreferences("Settings", 0);
                final String id = prefs.getString("ID", "");
                DefaultHttpClient httpclient = new DefaultHttpClient();
                HttpPost httpost = new HttpPost(
                        "http://iphone-radar.com/gps/gps_locations");

                JSONObject holder = new JSONObject();
...

What is going on?

Thanks

PS. I am using this because I want to call it with an alarm manager. However on button click I would like to show a progress dialog, where would I place the progress dialog for an intent service? (I've only had experience working with async tasks so far)

Sean
  • 1,123
  • 4
  • 24
  • 44
  • I'm no expert on this but don't you have to register your receiver AND set a filter for the particulat intent you wish to capture? When I've done this I did it in code but I think it can be done in the Manifest/xml too – D-Dᴙum Aug 29 '11 at 18:29
  • could you show me an example? Im not quite sure what you mean by filter – Sean Aug 29 '11 at 18:58
  • Sometimes you have given wrong `android:name` in `AndroidManifest.xml`, It may without package name – Pratik Butani Jan 17 '14 at 07:47

2 Answers2

15

Did you declare your service in AndroidManifest.xml? It won't be invoked unless it's declared like this:

<manifest ... >
  ...
  <application ... >
      <service android:name=".ExampleService" />
      ...
  </application>
</manifest>
Philipp Reichart
  • 20,771
  • 6
  • 58
  • 65
  • 1
    The name is relative to the `package` defined in the manifest tag. If your manifest tag has `package` defined as `com.example` and your service is in `com.example.data` then the name of the service will need to be `.data.ExampleService`. – Corey Ogburn Nov 07 '12 at 21:40
3

Adding the line below will allow you to step through the service. Make sure to remove it when you aren't debugging. If you don't the processing of your service will stop at that point and won't continue.

android.os.Debug.waitForDebugger();
bradley4
  • 3,823
  • 6
  • 34
  • 41