Monitor User Data Changes
By setting up a user data change listener, you can monitor changes to user information, group information, or group member user information (nickname).
Set Up a User Data Change Listener
Within the application lifecycle, after initialization but before connection, call the following method to set up a global information change listener UserDataObserver
.
RongUserInfoManager.getInstance().addUserDataObserver(userDataObserver);
UserDataObserver
provides the following callback methods:
onUserUpdate()
: This method is called when user information changes.onGroupUpdate()
: This method is called when group information changes.onGroupUserInfoUpdate
: This method is called when group member user information (nickname) changes.
The detailed definition is as follows:
/**
* User information change observer, all callbacks are on the UI thread
*/
public interface UserDataObserver {
/**
* Callback method when user information changes.
* @param info The updated user information.
*/
void onUserUpdate(UserInfo info);
/**
* Callback method when group information changes.
* @param group The updated group information.
*/
void onGroupUpdate(Group group);
/**
* Callback method when group member user information (nickname) changes.
* @param groupUserInfo The updated group nickname information.
*/
void onGroupUserInfoUpdate(GroupUserInfo groupUserInfo);
}
Remove the User Data Change Listener
You can remove the previously set listener using the following method.
RongUserInfoManager.getInstance().removeUserDataObserver(userDataObserver);