I created another class where I have function of logout:

```
fun logOut(context: Context) {    
        context.stopService(Intent(context, CheckNewMessages::class.java))
        val intent = Intent(context, LoginScr::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP and
                Intent.FLAG_ACTIVITY_NEW_TASK and
                Intent.FLAG_ACTIVITY_NO_ANIMATION
        context.startActivity(intent)

        (context as Activity).finish()
    }

```

and as you can see I use this line for finishing activity:

```
(context as Activity).finish()

```

But it is still alive and as a result I have two or more same activities at my system. I tried a lot of ways like creating static variable at first activity and using this variable at the second one for closing. But my activity stays alive. I also tried to use lauchmode at manifest and some other ways. Maybe someone knows where I did a mistake?

UPDATE
------

Two places from which I call `logOut()`. 1st is interface between RV adapter and fragment:

```
override fun finish() {
        APICallRequests.logOut(context!!)
        activity!!.finishAffinity()
    }

```

and 2nd at `Interceptor` for requests:

```
private fun updateAccessToken(context: Context) {
        val sp = context.getSharedPreferences(Constants.SHARED_PREFS_STORAGE, 0)
        synchronized(this) {
            val tokensCall = accessTokenApi()
                    .getNewToken(ReqAccessToken(sp.getString("refresh_token", "")!!))
                    .execute()

            if (tokensCall.isSuccessful) {

            } else {
                when (tokensCall.code()) {
                    500 -> {
                        val thread = object : Thread() {
                            override fun run() {
                                Looper.prepare()
                                Toast.makeText(cont, cont.getString(R.string.server_error_500), Toast.LENGTH_SHORT).show()
                                Looper.loop()
                            }
                        }
                        thread.start()
                    }

                    401 -> {
                        APICallRequests.logOut(context)
                    }
                }
            }

        }
    }

```