Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put interface in bundle to start a new activity

I need to start an activity from 2 different screens that have two different models but, both models have some shared information which is the one that I need in the new activity. The problem is that I cannot make those models to extend from the same parent, as one of the models already extends one parent. I have thought about creating an interface that contains the shared methods but, if I do that, then how can I put that interface in the bundle required to start the next activity?

I add some simplified code in order to clarify my situation:

public class A extends Model implements CustomInterface {
    String name;
    String address;

    public String getName(){
        return name;
    }

    public String getAddress() {
        return address;
    }
}

public class B implements CustomInterface {
    String name;

    public String getName() {
        return name;
    }
}

public interface CustomInterface {
    String getName();
}

My problem is that I need to start an activity with a bundle with the shared information between both models. So, I would like to put CustomInterface in a bundle. How could I do that?

Thanks in advance.

like image 417
FVod Avatar asked Jan 13 '16 18:01

FVod


1 Answers

So, I would like to put CustomInterface in a bundle

you could let CustomInterface extend Parcelable. E.g.

 public interface CustomInterface extends Parcelable {
     String getName();
 }

this way the classes implementing CustomInterface will have to implements the method defined in the Parcelable interface. If implemented correctly, you will be able to pass those objects around without problems

like image 149
Blackbelt Avatar answered Oct 28 '22 02:10

Blackbelt