lundi 18 mai 2015

Is there a quicker way to create a callback than interfaces or handler?

I just want to check if there may be a simpler way to do this.

If i have some generic ASyncTask and it's done i want to pass a success boolean back to the original caller. Normally i create an interface inside the custom AsyncTask class with just one method void onSuccess(boolean success); The caller would implement that and so on.

I just feel that it clutters the project with mini interfaces.

I could also pass along a handler, but i would have to create a handler for only that purpose which often feels like "just a bit too much code for the purpose".

I could pass a runnable along, but i would have to fire it on a thread and that could cause trouble.

What i want i to execute a method of the calling object when the asynctask has finished. In Objective C i can pass along a "block" of code and maybe there is something similar in Android.

It is a theoretical question and there is no urgency, just curiosity.

Aucun commentaire:

Enregistrer un commentaire