Single sign on implementation of “pushed offline” function on Android

Single sign on (pushed offline)

The so-called function of being pushed offline, that is, an account keeps logging in at client a, and then logs in at client B, then client a will be pushed offline.

The server needs to return a token. Each time the app logs in, it assigns a new token to the app. If the token passed by the app in a request is not the latest, it is deemed that it needs to log in again. If the token fails, it returns the agreed code

How does app know that the account has been logged in on other devices? There are three implementations

Our project integrates the instant chat of Huanxin, so we use the listener of Huanxin to monitor the user status to judge whether it has logged in elsewhere and realize the offline squeeze function.

1. First, set a global listener to register a connection listener when initializing the ring message.

2. To implement this connection monitoring, when the user detects that the connection is disconnected, judge whether the user is removed or the connection conflict, that is, the account logs in elsewhere and makes corresponding operations.

3. We only care about the account logging in elsewhere. At this time, we usually jump to mainactivity, and then force a pop-up dialog box to prompt the user to log in again.

After detecting the login conflict, this place needs to return to the mainactivity and carry an identification and a flag bit intent.flag for the mainactivity_ ACTIVITY_ NEW_ Task means to open an activity in a new task. If the task containing the activity is already running, the activity will return to the foreground display. It then calls back to the onnewintent () method to process the intent.

4. Go back to the onnewintent method in mainactivity

First, the identification will be judged. If it is an account conflict, a dialog box will pop up to prompt the user to jump to the login page and log in again. In addition, this dialog box cannot be cancelled or closed.

In this way, the function of being squeezed offline is basically realized.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>