Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meant by Activity-scoped listener in android?

**A snap from the documentation of firebase**

What is meant by Activity-scoped listener? And how is it different from a simple addOnCompleteListener like this!

like image 555
Muhammad Muzammil Avatar asked Jun 13 '16 09:06

Muhammad Muzammil


1 Answers

An Activity-scoped listener is a listener for you specify an activity when you register it.

From the docs you linked:

public Task<TResult> addOnCompleteListener (Activity activity, OnCompleteListener<TResult> listener)

Adds an Activity-scoped listener that is called when the Task completes.

The listener will be called on main application thread. If the Task is already complete, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.

The listener will be automatically removed during onStop().

That last bit (emphasis mine) is crucial: when you register a listener with an activity scope, it won't be called if that activity is not active anymore. This is great for listeners that for example need to show their data in the activity.

like image 147
Frank van Puffelen Avatar answered Sep 20 '22 01:09

Frank van Puffelen