0

My question is as follows:

I started my intentService from my main Activity. This intentService does some audio processing with audioRecord.

However, when I need to start another activity in my application (recording video in this case), i need to stop the intentService in the background (because it is hogging the audio resource).

Is there a way to stop the intentService from the main activity?

dandyling
  • 45
  • 8

2 Answers2

0

You can use stopService() from your main activity like this:

stopService(new Intent(yourMainActivity.this,yourIntentService.class));
Augusto Picciani
  • 788
  • 2
  • 11
  • 31
0

use the same pre-declared intent which you used to start the IntentService and call

stopService(intent);

if you create a new intent and use it to stop the service, the service will not respond to it until its finishes processing the previous intent.

but it should be noted that this will not immediately stop the service. So a workaround to this is to have a Global boolean variable. When its set to true the processing within the service will carry out, and when you want to end it set the boolean variable to false from your activity. and then you can stop the service from within itself by calling

stopSelf();
Poonam Anthony
  • 1,848
  • 3
  • 17
  • 27