I am using android TabWidget and I have one main activity where I am managing all the tabs. Each tab has his own activity:
private void setTabs()
{
addTab("News", NewsActivity.class);
addTab("Project", ProjectActivity.class);
addTab("About", AboutActivity.class);
addTab("Contact", ContactActivity.class);
}
The data for each tab is downloaded from the server in JSON format. My goal is to download all the data on the oppening of the application and then to use it for each tab (activity).
Is there a possibility to share those variables from the main activity to the others where I am managing the tabs? I know about using the Intent class but may be there is another easier solution with the tabs.
Thank you very much.
Declare static variables in your main activity and store the data in them.
For example, public static integer myInt;
myInt = ...;
Now when you go to the other Activities, just use MainActivity.myInt to access its value and even update it if you want. No need to pass the variable around using intents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With