0

i want to have a function in one class, that does an animation and then notify''s a function that is passed to it which is in another class. how do i do that ?

exapmle: in my scanning barcode activity i have:

 public void callbackFNC () {
    //this is the callback bunction
}

from scanning barcode activity i'm calling a function that is in another activity like (i want to pass the callback that is in scanning barcode activity as parameter there) :

loadToastModule loadToastMD = new loadToastModule();
loadToastMD.doEvent(toastModel);

then in doEvent that sits in LoadToastModule.class function i want to have

public void doEvent(LoadToast toastModel) {
        toastModel.error();



        new CountDownTimer(0, 500) {

            public void onTick(long millisUntilFinished) {
                //do nothing
            }

            public void onFinish() {

               ****DO THE CALLBACK HERE
               ****DO THE CALLBACK HERE

            }
        }.start();
  • it is important to me that i'll use it like this instead of just calling a PACIFIC function because in the future i want to use the same function with different callback.

thnx !!!

Chief Madog
  • 1,738
  • 4
  • 28
  • 55

1 Answers1

1

Another ways can be to use Handler or Interfaces. For using handler, checkout the answer by @FoamyGuy. You can extend his code to pass strings or whatever you want. Something like:

Pass in handler from where you are calling the method.

Handler handler = new Handler(){
    @Override
    public void handleMessage(Message msg){
        if(msg.what == 1){
           //Success
           String msg = (String)msg.obj;
           Log.d("", "Msg is:"+msg);
        }else{
           //Failure
           String msg = (String)msg.obj;
           Log.d("", "Msg is:"+msg);    
        }
    }
};

loadToastMD.doEvent(toastModel, handler);

Send the message back based on whatever happened there:

public void doEvent(LoadToast toastModel, Handler handler) {
    ....
    public void onFinish() {
       ****DO THE CALLBACK HERE
       ****DO THE CALLBACK HERE
       Message m = handler.obtainMessage(1, "Success finish message string");
       m.sendToTarget();
    }
}
Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124