Listener Issues Android SDK 9.6

59 views
Skip to first unread message

raje...@mondays.in

unread,
Oct 28, 2016, 10:52:55 AM10/28/16
to Firebase Google Group
Hi, 

I'm building an android application using Firebase Android SDK 9.6. I'd like to know few things, I've searched all your docs but I can't find any resources. So here are my questions,

I've a login activity and home activity. Once I was loggedin i'll not be redirected to login activity unless i clicked logout.

1. So, when I register a value event listener in login activity class, some times it getting the changes and sometimes it is not. Is that something like value event listeners will work only if the class is running. 

2. If i've some 5 listeners in home activity, will it be registered each time when home activity is created. Do i've to unregister all listeners when my app is destroyed, or firebase sdk will take care of that automatically.

Regards,
P.Rajesh.

Kato Richardson

unread,
Nov 2, 2016, 8:12:52 PM11/2/16
to Firebase Google Group
Hi P.

Everything here is dependent on how you've implemented the listeners. For example, onCreate() would only be executed once per app lifecycle (and could be used to establish listeners that you want to invoke exactly once), where onResume() would be used each time a user leaves and returns to the activity (whether the app is still active or not).

You can also cancel listeners in onPause(), onStop(), and onDestroy() to ensure duplicate listeners are not created.

Check out this great diagram of the event lifecycle, which I reference from time to time when designing my apps.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/c393e423-e1b3-4aa4-962e-603144f95aad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Doug Stevenson

unread,
Nov 3, 2016, 4:58:04 PM11/3/16
to Firebase Google Group
To add to what Kato said, it's conventional in Android to register and unregister things like listeners and broadcast receivers in complimentary parts of the Android activity lifecycle.  So each pair of callbacks could be used for add and remove operations:

onCreate/onDestroy
onStart/onStop
onPause/onResume

Typically, onStart/onStop are used for most things, because this reflects when the activity is visible to the user.

Doug

On Wednesday, November 2, 2016 at 8:12:52 PM UTC-4, Kato Richardson wrote:
Hi P.

Everything here is dependent on how you've implemented the listeners. For example, onCreate() would only be executed once per app lifecycle (and could be used to establish listeners that you want to invoke exactly once), where onResume() would be used each time a user leaves and returns to the activity (whether the app is still active or not).

You can also cancel listeners in onPause(), onStop(), and onDestroy() to ensure duplicate listeners are not created.

Check out this great diagram of the event lifecycle, which I reference from time to time when designing my apps.

☼, Kato
On Thu, Oct 27, 2016 at 11:18 PM, <raje...@mondays.in> wrote:
Hi, 

I'm building an android application using Firebase Android SDK 9.6. I'd like to know few things, I've searched all your docs but I can't find any resources. So here are my questions,

I've a login activity and home activity. Once I was loggedin i'll not be redirected to login activity unless i clicked logout.

1. So, when I register a value event listener in login activity class, some times it getting the changes and sometimes it is not. Is that something like value event listeners will work only if the class is running. 

2. If i've some 5 listeners in home activity, will it be registered each time when home activity is created. Do i've to unregister all listeners when my app is destroyed, or firebase sdk will take care of that automatically.

Regards,
P.Rajesh.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/c393e423-e1b3-4aa4-962e-603144f95aad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages