I can suggest 3 options
1 Option
Use singleton, or simply define a class as static.
public class Singleton {
private static Singleton uniqueInstance;
private Singleton() {
}
public static synchronized Singleton getInstance() {
if (uniqueInstance == null)
uniqueInstance = new Singleton();
return uniqueInstance;
}
}
Read more at: Java Singleton Project Pattern link
2 option
Defining global variables or objects, you can create a Class Application on Android and set global variables or even the singleton.
Example .
3 Option
You can pass variables or objects by Intent to other activities or fragments
Activity 1
Intent i=new Intent("....");
i.putExtra("TEXT", "Olá");
startActivity(i);
Activity 2
TextView text = (TextView) findViewById(R.id.text);
Bundle bundle = getIntent().getExtras();
String var_intent = bundle.getString("TEXT");
text .setText(var_intent );
Read more.