Skip to content Skip to sidebar Skip to footer

Having Trouble With Interfaces In Java Regarding Retrieval And Storage Of Data From A Firebase Database

When I run the following code: I get the toast messages in the following order: 'Inside mCheckInforInServer' --> 'Posted text' --> 'Took Value' How do I change my code to get

Solution 1:

You cannot change the order of displaying those Toasts because onDataChange() method is called asynchronous which means that the Toast that you are trying to display Posted text is called even before you are trying to get the data from the database. That's why you are having that order of execution.

To solve this, all you need to get from the database must be used inside onDataChange() method otherwise will be null.

If you want to use the data from the database outside onDataChange() method, i suggest you see my answer from this post.

Post a Comment for "Having Trouble With Interfaces In Java Regarding Retrieval And Storage Of Data From A Firebase Database"