如何在所有活动中保留数据 [英] how to persist data across all the activities

查看:80
本文介绍了如何在所有活动中保留数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表单,登录成功后我需要在所有屏幕上显示用户名。我尝试使用意图,但名称在所有活动中不一致,有些屏幕显示用户名和其他人null。有没有其他方法来实现这个目标?



这就是我现在的表现。但结果不一致

i have a login form where after successful login i need to display the name of user in all the screen. i tried it using intents but the name is not consistent across all the activities some screen shows username and others null. is there any other way to achieve this?

this is how i did now. but the result is not consistent

Intent next=new Intent(getApplicationContext(),RoomsConfiguration.class);
                next.putExtra("iUserID",iUserID);
                startActivity(next);







Intent next=getIntent();
        iUserID = next.getStringExtra("id");
        tv.setText(new StringBuilder().append("Logged as ").append(iUserID));

推荐答案

为了管理用户详细信息,使用 SharedPreferences [ ^ ]

参考本教程: http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/ [ ^ ]



-KR
For managing the user details, you use SharedPreferences[^]
Refer this tutorial: http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/[^]

-KR


对于初学者,您使用的是iUserID来设置数据和ID得到它。
For starters you're using iUserID to set the data and id to get it.


这篇关于如何在所有活动中保留数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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