Android token expired jump to login interface problem

when the server returns 401, jump to the login interface.

the problem is: if there are multiple requests in an interface, there will be multiple jumps to the login interface. How to solve this problem?

Mar.05,2021

set the launchMode of the login interface to singleTop.

android:launchMode="singleTop"

this kind of problem can be solved logically
  1. when the first request returns 401, you should erase the local logged-in user data, then destroy the current page and cancel all request monitoring, and finally jump to the login page.
  2. when the second request returns 401, because the request listening has been cancelled, the subsequent jump operation will not be performed (plus a judgment condition: check whether the local user has been erased, once erased, the jump will not be performed)

you can refer to the logic of "press exit again" to add a time control when dealing with expiration logic.
you can use the takeFirst operator if you use Rxjava.

Menu