Event Listening in a lib

1

I am building a lib but at the end of the process it performs I need to let me know that it has finished, how can I implement this? Any ideas?

In the project that uses lib I do this:

Lib lib= new Lib (getActivity());      
lib.iniciaInteratividade();

In this initializationInteractive () a Dialog is shown and it is done all a step by step, in the end I wanted to be warned that it is finished.

Thank you.

    
asked by anonymous 02.08.2016 / 18:25

2 answers

2

If you want to listen to an event, then create one.

A simple way to do this is to define an interface that the "listener" object must implement to be notified when the event occurs.

Start the interface by declaring it in the Lib class:

public interface OnFinishListener{

    public void onFinish();
}

If you want to pass some information to the listener, declare parameters in the interface method ( onFinish() )

Declare a method to tell the Lib class which listener wants to be notified:

//Atributo para guardar o "ouvinte"
private OnFinishListener listener;
public void setOnFinishListener(OnFinishListener listener){
    this.listener = listener;
}

When you want the Lib class to notify the "listener" use:

if(listener != null){
    listener.onFinish();
}

To use do so:

Lib lib = new Lib (getActivity());
lib.setOnFinishListener(new OnFinishListener(){
    @Override
    public void onFinish(){

        //Coloque aqui o código a ser executado quando receber a notificação.
    }
});  
lib.iniciaInteratividade();
    
02.08.2016 / 20:17
0

Speak Marcelo,

You can create a boolean variable (in activity), and when you finish the Dialog process you change this to true.

Does not resolve?

Hugs.

    
02.08.2016 / 20:14