How is it to test purposes (because there is no bank yet), you can create a Singleton by launching the application. This object stores static information, which means you can access it from anywhere in the application.
public class SingletonUsuario {
private static SingletonUsuario instance = null;
private static Usuario usuario = null;
public static SingletonUsuario getInstance() {
if (instance == null) {
usuario = new Usuario();
return instance = new SingletonUsuario();
} else {
return instance;
}
}
public void setUsuario(Usuario usuario) {
SingletonUsuario.usuario = usuario;
}
public Usuario getUsuario() {
return SingletonUsuario.usuario;
}
}
To use it, just call:
Usuario u = new Usuario();
u.setNome("Joãozinho");
SingletonUsuário.getInstance.setUsuario(u);
To get the information from anywhere in the app
txtView.setText(SingletonUsuario.getInstance.getUsuario.getNome); // retorna a string nome
This way, in any Activity your user will be "saved" in ram memory and will not disappear until the application is terminated.
How do you do it? Could you show so someone can help?
– durtto
This may help you. https://developer.android.com/training/basics/data-storage/shared-preferences.html?hl=pt-br
– Reginaldo Rigo