简体   繁体   English

在Android中使用当前用户的最佳方法

[英]Best way to user current user in android

When i get a user by json request in android i have a one class, example: 当我在android中通过json请求获得用户时,我只有一个类,例如:

public class CurrentUser {
    public static String first_name = "";

    public static String getFirst_name() {
        return first_name;
    }

    public static void setFirst_name(String first_name) {
        CurrentUser.first_name = first_name;
    }
 }

and i class in mi activity class 我在mi活动课上课

my_text.settext(CurrentUser.getFirst_name());

But when app is in background i lose the data, existing any options without shared preferences? 但是,当应用程序在后台运行时,我会丢失数据,是否存在没有共享首选项的任何选项?

There is more than one option but all leads to the same. 有一个以上的选择,但所有选择都导致相同的选择。 You need to store this data manually. 您需要手动存储此数据。 Using a saveInstanceState is an option, but it won't survice app closing. 使用saveInstanceState是一个选项,但不会阻止应用程序关闭。 Other hand you can store it to the database using sqlite / realm or whatever you like. 另一方面,您可以使用sqlite / realm or任何您喜欢的东西将其存储到数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM