I am trying to implement a login status monitoring in my application. What I am trying to achieve is calling an API in background service continuously. It will give a response depending on if the user is eligible to remain logged in. If the response states the user is not eligible to remain logged in, then the app should log out.

**How I Implemented this**

I created a foreground service and called the API inside an `AsyncTask` method. I called this method inside the service's `onStartCommand()` method.

**My doubts**

1. Is this the proper way to implement this work flow?.
2. I called the login activity from service like this

```
    Intent dialogIntent = new Intent(BluetoothLeService.this,SplashScreen.class);
    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(dialogIntent);

```

How do I finish the Activity from the service?

**EDIT- Why Iam trying this way**

If a user's activation is removed manually from back end then according to this work flow app will sign out automatically.Basically my app is a BLE based alert system.So logout after certain time is not possible.The only situation for logout is if the back end (ie; the service providers) find that user is not eligible for using the service, they will change the mentioned API result is to false.Due to this scenario I calls the API all time.What will be a better workaround for this?