I will try to keep it short and simple. I have a foreground service A
with broadcast receiver
. Some times it calls Service B
twice.
I want service B
to finish its execution first and if another request comes to run it again, it should remain awaiting until earlier execution finish. Thats why i have created Service B as IntentService
. But as call log is still not updated, i am sleeping service B for 2 seconds.
But when i implemented runnable in IntentService..., It left its original behaviour and if another request comes, both requests are running Service B concurrently.
My Service Broadcast receiver :
Log.d("RECEIVER X: ", "CALL ENDS HERE...");
Intent SendSMS = new Intent(context, SendSMS.class);
startService(SendSMS);
My IntentService :
public class SendSMS extends IntentService
{
public Boolean IsRunning = false;
public SendSMS()
{
super("SendSMS");
Log.d("SendSMS : ", "
OnCreate...");
}
@Override
protected void onHandleIntent(Intent intent)
{
new Thread(new Runnable()
{
public void run()
{
if(IsRunning == false)
{
IsRunning = true;
Thread.sleep(2000);
// perform operations here...
}
}
}).start();
}
}
My operations should be performed twice , But after first is finished with sleep of 2 seconds. Any help will be appreciated. Thanking you in advanced
See Question&Answers more detail:os