JarsOfJam-Scheduler
JarsOfJam-Scheduler

Reputation: 3169

Firestore: When should I detach the snapshot listener which updates a TextView in the navigation DrawerLayout?

In my navigation drawer layout, I show the user's login in a text view. The later can be changed if he clicks on a button titled "Edit profile" and then submits the corresponding form. That's why I use a snapshot listener, which updates the text view.

Since the navigation drawer layout exists at any execution time, when should I detach the listener?

I could detach it if the user clicks on the button "Log out", but what if he never clicks on it?

Upvotes: 1

Views: 128

Answers (1)

Bo Z
Bo Z

Reputation: 2607

The better practice will be save login in sharedPref first time and get it all the time for setting in the textView when needed. So in this case you don't need to make requests all the time drawer open. The second advantage will be it will work much faster. Third advantage is you will reduce the number of requests instead of making requests all the time you will just make request to update if needed so instead of thousands several same reading requests you will make one update request and everything gonna happen locally. And even if user will not have internet connection textView will show needed information. And you will not pay money in case you get a lot of users for latency to google cloud. Also it answer the question of what to do with listener

Upvotes: 1

Related Questions