I am working on an android application (mostly trying to figure out using RxJava / Android). These are my requirements:
- Maintain a consistent and global state for the registered user
- Whenever a user state changes, it updates the views accordingly.
I use a singleton instance Userto maintain global state and SharedPreferencesto save. Now I'm trying to use RxAndroid to notify changes in views, but I don't know how to do this.
How do we track changes in User? Can I use setters in Userto emit from observables; if so, how do I do this?
I would really appreciate if anyone could provide code samples too.
PS This is a sample class definition User, I did not use any setters.
public class User {
public String userName;
public String emailId;
public List<Friend> friends;
public User() {
friends = new ArrayList<Friend>();
}
}
public class Friend {
public String userName;
public String emailId;
public String role;
}
This is just a sample of the skeleton of my User class (I removed everything else), I just need to know how the setters will look for these fields, and if this approach is even considered correct or if they are the best alternatives.
Please let me know if you need more information.
source
share