I have a activity that start and stop a service. It seems to be simple but if i start service and stop it it is ok.
But when I restart the service I found two instances of the service.
Why?
public class Test extends AppCompatActivity implements View.OnClickListener {
@Override
public void onClick(View v) {
switch ( v.getId() ) {
case R.id.InitButton:
{
startMonitor();
}
break;
case R.id.EndButton:
{
stopMonitor();
}
break;
case R.id.SendData:
{
sendData();
}
break;
default:
break;
}
}
...
private void startMonitor(){
Intent intent = new Intent( this, MyService.class );
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startService( intent );
}
private void stopMonitor(){
Intent intent = new Intent( this, MyService.class );
stopService( intent );
}
If I click "initButton" Service start
Then I click "EndButton" and Service end
Then I click "initButton" again and start two services
I see the post suggested but my service is not in running when i stop it in activity