Search code examples
androidandroid-intentparcelable

Android: put Interface to Intent


I have a custom dialog in my app. My custom dialog I implemented as Activity with transperent background and with view like dialog. Mu custom dialog looks like alert dialog, with title, message and button. What I'm tryin to do, is to create nice interface for setting title, message and onClickListener of my popup.

Firstly I thout to put all staff to intent like:

 Intent intent = new Intent (this, CustomPopup.class);
 intent.putExta ("Title", "PopupTitle");
 intent.putExta ("Message", "PopupMessage");
 intent.putExtra ("OnCLickListener", ?????); //here is problem

 startActivity(intent);

But the problem is that is no way to pur OnCLickListener to intent.

Secondly, I tried to create class that implement Parcable. But the problem is the same

@Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(title);
        dest.writeString(message);
        dest.writeValue(buttonClickListener); // here is problem. I cannot write Interface
    }

I cannot write OnCLickListener to Parcel object.

How to be ? How to write nice interface to my custom popup ? Because popup can have different titles and messages, and popup will be used from many activities....Thanks in advance


Solution

  • Create a class that implements both OnClickListener and Serializable. Send an instance through the Intent to the "dialog".