Question

here's an example of what I'm trying to do

 public class BookModel {

        private void update_method() {
            get_info task = new get_info(this)
            task.exicute(some args); 
        }

        public void finishedCallback(some_return_type result) {
        // do some stuff when finsiehd. 
        }


    class get_info extends AsyncTask<HashMap<String, String>, Void, dataType>
    {
        private BookModel bookModel; 

        public get_info ( BookModel reset) {
            bookModel = reset; 
        }

        @Override
        protected dataType doInBackground(arg...)
                        some procscessing. 
        }

        protected void onPostExecute(dataType result) {
            bookModel.finishedCallback(result);
        }
    }
    }

How can i get this callback system to work... I tried using an inteface as well, but it did not work. I think it's because you need 3 classes with an interface (correct me if I'm wrong). also I'm open to any suggestions, but Ideally I would like to keep this functionality within the same class if possible. any help with this would be greatly appreciated.

Was it helpful?

Solution

try this.

this is worked for me.

 public class BookModel implements get_info.xyz {

    private void update_method() {
        get_info task = new get_info(this);
        task.exicute(some args); 
    }

    public void finishedCallback(String result) {
    // do some stuff when finsiehd. 
    }

 }
//----------------------------------
class get_info extends AsyncTask<HashMap<String, String>, Void, dataType>
{


    private xyz bookModel; 
    public interface xyz
    {
       void finishedCallback(String str);
    }
    public get_info ( xyz reset) {
        bookModel = reset; 
    }

    @Override
    protected dataType doInBackground(arg...)
                    some procscessing. 
    }

    protected void onPostExecute(dataType result) {
        bookModel.finishedCallback(result);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top