仅允许活动用户登录 [英] Allow only active user to login

查看:64
本文介绍了仅允许活动用户登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android工作,我想实现,当用户登录应用程序时,有一个检查。如果用户处于活动状态,他/她可以登录,或者如果他/她阻止用户,他不会?任何人都可以这样指导我吗?



我尝试过:



i尝试共享首选项但是没有得到逻辑如何执行此操作

i am working in android and i want to implement that when the user login the app there is a check. If the user is active he/she can login or if he/she blocked user he wont? can anyone please guide me this way?

What I have tried:

i tried shared preference but em not getting the logic how to do this

推荐答案

Android提供了SharedPreferences类,允许应用程序保留原始类型的数据,键值对形式的字符串,int,long,float和boolean。您可以使用getPreferences()方法创建当前活动专用的首选项文件。如果要将用户的状态存储为已阻止或活动,则可以在首选项文件中以userid-status的形式将其保存为键值对列表。

了解使用共享首选项 [ ^ ]。



话虽如此,如果每个用户都可以被阻止或活动,那么您只需要保留阻止用户或活动用户的列表,具体取决于哪个用户拥有较少的数据。我会选择阻止的用户列表,因为如果被阻止的用户将来恢复活动状态,列表可能会缩短,对吗?在这种情况下,我建议使用 SQLite数据库 [ ^ ]您可以在表格中插入用户数据然后通过强大的SQL操作来操作它们。
Android provides the "SharedPreferences" class that allows an app to persist primitive type of data, such as string, int, long, float, and boolean, in the form of key-value pairs. You can use getPreferences() method to create a preference file that is private to the current activity. If you want to store the user's status as either "blocked" or "active", you can save them as a list of key-value pairs in the form of userid-status in the preference file.
Learn Using Shared Preferences[^].

Having said that, if every user can be either blocked or active, then you just need to keep a list of either blocked users or active users depending on which one has fewer data. I will go for the blocked users list as the list can get shortened if blocked users get reinstated to active in the future, right? In this case, I would recommend using SQLite Databases[^] where you can insert user data in tables, then manipulate them through the powerful SQL operation.


您可以根据服务器上或本地sqlite数据库中的数据库中的登录来保存用户状态。当用户登录时检查状态是否被阻止然后不允许登录,反之亦然。
You can save user status against their logins in the database on server or on local sqlite database. When a user login check the status if it is blocked then don't allow to login and vice versa.


这篇关于仅允许活动用户登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆