I want use variable of onDataChange method to use outside of the method can someone help me through this?
Asked
Active
Viewed 12 times
0
-
There is no way you can `mCity` outside the callback. Firebase API is asynchronous. So please check the duplicate to see how can you solve this using a callback. You might also be interested in reading this [resource](https://medium.com/firebase-tips-tricks/how-to-read-data-from-firebase-realtime-database-using-get-269ef3e179c5). – Alex Mamo Jan 18 '23 at 14:32
-
i did with shared preference is this a good idea or not? – Afaque Memon Jan 22 '23 at 06:43
-
SharedPrefs doesn't persist across app uninstalls. If that's not a problem, then you can go ahead with it, otherwise save the data in the Cloud. – Alex Mamo Jan 22 '23 at 15:05