[英]Android Java: Error in setting parameter sent from one activity to another java class
I have an Activity 'LoginPage' which contains pwd and email.我有一个包含密码和电子邮件的活动“登录页面”。
Once logged in, i am sending the 'email' value as a parameter at some random point to a class 'EmailDetails' in the following manner:-登录后,我将通过以下方式将“电子邮件”值作为某个随机点的参数发送到“电子邮件详细信息”类:-
obj.setEmail(email); //where obj is object of EmailDetails
'EmailDetails' contains the following code:- 'EmailDetails' 包含以下代码:-
public class EmailDetails
{
public String Usermail;
public void setEmail(String email)
{
Usermail = email; //Username='null' & email='XYZ@yahoo.co.in'
}
public String getEmail()
{
return Usermail; //Username='null'
}
}
When some other random activity 'X' wants to access 'email' value in the following manner:-当其他一些随机活动“X”想要通过以下方式访问“电子邮件”值时:-
email=obj1.getEmail(); //where obj1 is Object of EmailDetails
The 'email' value return null. 'email' 值返回 null。
So, where am i going wrong in the code?那么,我在代码中哪里出错了? Thanks.
谢谢。
You have to use intents to send data from one activity to another in android This link might help you http://www.c-sharpcorner.com/uploadfile/kirtan007/passing-data-from-one-activity-to-another-activity-in-android/ 您必须使用意图将数据从一个活动发送到android中的另一个活动。此链接可能会帮助您http://www.c-sharpcorner.com/uploadfile/kirtan007/passing-data-from-one-activity-to-another-在Android活动/
If this will help you accept the answer as true So,it will be helpful for others too. 如果这将帮助您接受正确的答案,那么对其他人也将有所帮助。
Are you storing the data you get from user somewhere? 您是否将从用户那里获得的数据存储在某个地方? I mean does this EmailDetails class persists somewhere outside of the login activity?
我的意思是,此EmailDetails类是否在登录活动之外的某个地方持续存在? try using shared preferences as most simple data persisting storage.
尝试使用共享首选项作为最简单的数据持久存储。 Here's one of most popular answers on this matter on SO How to use SharedPreferences in Android to store, fetch and edit values
这是关于此事的最流行的解答之一,因此如何在Android中使用SharedPreferences来存储,获取和编辑值
Hope this helps! 希望这可以帮助!
The value is null
because you used this
operator, it should be该值为
null
因为您使用了this
运算符,它应该是
public void setEmail(String email)
{
this.Usermail = email; //Username='null' & email='XYZ@yahoo.co.in'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.