This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Accessing the GenericOnOffStatus in nRF Mesh Android Activity after doing a GenericOnOffGet

As per one of my discussions with , on another thread here, I can send a GenericOnOffGet from my android activity and I will get the status of the light in GenericOnOffStatus construct.

But the code from Nordic employs the use of mViewModel which through many layers of abstraction uses the MeshManagerApi of the MeshService running in the current context.

But I don't want to use mViewModel if I can directly connect to MeshManagerApi of the MeshService.

Is there a way to access the GenericOnOffStatus using MeshManagerApi of the MeshService? If not, which route should I go? Meaning, how should I get access to GenericOnOffStatus which uses the same context as the running MeshService from my Activity? What is the handle I should use in my activity to access this?

I can see in the debug Log the GenericOnOffStatus coming. But, I guess it's from the mViewModel construct (correct me if I'm wrong on this). I don't want it from mViewModel. I want it directly from the MeshmanagerApi of the service.

Parents
  • Hi Xavier, The reason for using a ViewModels is to adhere with the new Architecture Components by Android. This separates a lot of the logic  that had to be written within an activity class.This also handles Configuration changes and lifeycle of activities in Android avoiding us developers needing to save complex UI states across orientation changes. The ViewModel has a reference to the particular repository we are talking to. Whenever a status message is received the activity observing the particular LiveData object will be notified.

    During our last discussion you decided to bind to the service directly without the use of ViewModels which also is fine.

    What you may do is to register a broadcast receiver in your activity, this way you can notify your activity for any events that occur in the service. I have used the same approach to notify events from the service to a particular repository. In your case you might want to look at BaseMeshRepository and these broadcasts are sent from the MeshService.

  • Hi Roshan. Isn't there a way to know whom GenericOnOff status is? I send the GenericOnOffGet, but the observer can only tell me when the status changes, but not who's the source of that status. I cannot know which node has that change.

  • @Jackes5 we would really aopappreci if you had created a new ticket for new questions. This was simesomet missing in the library, but the latest dev branch has added new changes that include this.

Reply Children
Related