'Do I have to use Bundle for data exchange between activity and fragment?
Multiple Fragments are created in one Activity to switch pages to Fragment binding. At this point, the data in Main Activity must be used by all fragments.
So I did it like this. I called method in Activity that return data in activity. ↓ fragment.java
MainActivity main = (MainActivity) getActivity();
data = main.getCurrentUserID();
And this is getCurrentUserID() in MainActivity.
public String getCurrentUserID() {
Intent intent = new Intent();
String curUser = intent.getStringExtra("USER ID");
return curUser;
}
This way, no data is loaded. Why is that? How can I take out items in one Bundle from multiple fragments to use Bundle?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|