I have a pojo method that generates a Bitmap. When done, I want to throw the Bitmap to a UI Activity. This is a sample, but here it is:
private void sendBitmap(Bitmap bitmap) {
// TODO - I'm in the pojo where I want to send the bitmap
}
FYI: The UI Activity that I want to notify is outside of my project. I mean, my project is an SDK, such that another developer would be grabbing this information as soon as it becomes available.
I've been trying to figure this out but getting somewhat confused.
- Do I need a "callback" interface?
- Or a "listener" interface?
- Or both?
I have created a Callback Interface in my MyActivity. So far, so good. This is what it looks like so far:
import android.graphics.Bitmap;
public class MyActivity {
// protected void whateverOtherMethods (Bundle savedInstanceState)
// {
// .
// .
// .
// .
// .
// .
//
// }
/**
* Callback interface used to supply a bitmap.
*/
public interface MyCallback {
public void onBitmapReady(Bitmap bitmap);
}
}
The demo application's DoSomethingActivity can implement the Callback Interface that I have created. This is the implementation of the callback in the demo application's DoSomethingActivity:
private final MyCallback myCallback = new MyCallback() {
@Override
public void onBitmapReady(Bitmap bitmap) {
// TODO - do something with the bitmap
}
};
What is the step I'm missing to notify the callbacks? Maybe I almost have it, but I'm confused enough that I'm looking for a little help here.
UPDATE:
OK, I've added "implements" for my callback "BitmapCallback" interface into the pojo. Here it is:
public class ProcessImage implements BitmapCallback {
/**
* pojo method to return bitmap
*/
private void sendBitmap() {
this.onBitmapReady(bitmap);
}
@Override
public void onBitmapReady(Bitmap bitmap) {
// we still need to send the bitmap to cusomer App.
}
I cannot move the callback definition from the SDK Activity, because I want the customer's application to implement the callback in their code to handle the bitmap when it is returned to the customer's application.
Here is the callback interface in my Activity:
public interface BitmapCallback {
public void onBitmapReady(Bitmap processedBitmapy);
}
Here is the implementation in the customer's application:
private final BitmapCallback bitmapCallback = new BitmapCallback()
{
@Override
public void onBitmapReady(Bitmap bitmap) {
// TODO Auto-generated method stub
}
};
Call me dumb, but I'm having a hard time getting my head around this.