Issue
I have put extra with this code on my main activity like this:
Intent intent = new Intent();
intent.setClass(ItemMainActivity.this, (Class<?>) map.get("itemActivity"));
intent.putExtra("user",user);
intent.putExtra("userID",userID);
startActivity(intent);
When I try to get the extra by using this code, it returns null:
Intent intent = this.getIntent();
Bundle extras = intent.getExtras();
String user = null, userID = null;
if (extras != null) {
user = extras.getString("user");
userID = extras.getString("userID");
}
Toast.makeText(getApplicationContext(),"user: "+user+" id: "+userID,Toast.LENGTH_LONG).show();
How do I fix this?
Solution
I would like to suggest another way.... The concept of a common class. And make a public static variable of the data type which you need and set the value in the activity and access it wherever you need.
Public class Common{
Public static String userId ="";
}
Set value in this variable Common.userId = "YOUR_VALUE"
When need to access just use Common.userId
Feel free to ask if something is unclear.
Answered By - Kamal Nayan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.