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:
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
Post a Comment