java - Android firebase onStart and onStop explanation -


i've started firebase in android , can't understand things in onstart , in onstop.

why necessary have code on stop method? why need remove listener ?

@override protected void onstop() {     super.onstop();     log.d(tag, "onstop: ");     if(mauthstatelistener != null)         mauth.removeauthstatelistener(mauthstatelistener); } 

and 1 more question advantage of setting mauth listener in onstart method instead of oncreate ?

@override protected void onstart() {     super.onstart();     log.d(tag, "onstart: ");     mauth.addauthstatelistener(mauthstatelistener); } 

this how shoved in firebase -> authentication demo.

there need remove listeners because mauth keep of keeping track of listeners added, in order notify when happens.

when activity stops remove listener list because well, activity has stopped anyway, there no need listen auth events when activity stopped, there?

why add listener @ onstart then?

because according activity life cycle:

enter image description here

onstart , onstop correspond each other, while oncreate , ondestroy correspond each other.

if add listener in oncreate , remove @ onstop, listener not added when activity restarts, since oncreate not called on restart. onstart is.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -