Local Broadcast not updating UI


#1

i have this code in my register user activity:
val userDataChange = Intent(BROADCAST_USER_DATA_CHANGE)
userDataChange.putExtra(“aaa”, “aaaaaaaa”)
userDataChange.putExtra(“bbb”, 123)
LocalBroadcastManager.getInstance(this).sendBroadcast(userDataChange)

and in the main activity the reciever:
LocalBroadcastManager.getInstance(this).registerReceiver(userDataChangeReceiver,
IntentFilter(BROADCAST_USER_DATA_CHANGE))

and the userDatachangeReceiver function:
private val userDataChangeReceiver = object: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Log.d(“aaa”, AuthService.isLoggedIn.toString())
userNameNavHeader.text = "BBBBBBBBBBB"
if (AuthService.isLoggedIn == true) {
userNameNavHeader.text = userDataService.name
userEmailNavHeader.text = userDataService.email
val resourceId = resources.getIdentifier(userDataService.avatarName, “drawable”,
packageName)
userImageNavHeader.setImageResource(resourceId)

userImageNavHeader.setBackgroundColor(userDataService.returnAvatarColor(userDataService.avatarColor))
loginButtonNavHeader.text = “Logout”
}
}
}

the create user activity updates the userDataService(singelton) just fine,
when i log it i get the right parameters. the AuthService.isLoggedIn returns true but the drawer UI does not gets updated i have tryed to put it int the onStart, onResume unregister on onPause but no luck, also when i try to access the bundle inside the intent i get null. i put it there just to see if its really getting thrugh any ideas?

after i added these lines in the onCreate of MainActivity:
userNameNavHeader.text = "name"
userEmailNavHeader.text = "email"
userImageNavHeader.setImageResource(R.mipmap.ic_launcher)
and now the update goes well, can anyone help me understand why?


#2

This seems to be a question on Android programming in general; please ask it on StackOverflow instead.