T
T
terminator-light2019-06-16 13:11:16
Java
terminator-light, 2019-06-16 13:11:16

Is it practical to pass objects as a parameter to another controller in Conductor?

As I understand it, you can transfer, but can unforeseen situations happen?
CheckoutController:

public void init(){
     btn.setOnClickListener(v->getRouter().pushController(RouterTransaction.with(address == null ?  new AddressController(this) : new AddressController(address, this)));
}
@Override
public void setAddress(Address address) {
     this.address = address;
     tvAddress.setText(address.street+" "+address.house);
}

AddressController:
public <T extends Controller & CheckoutListener> AddressController(Address address, T listener) {
        this(new BundleBuilder()
        .putString("street", address.street)
        .putString("house", address.house)
        .build());
        setTargetController(listener);
}

public AddressController(Bundle bundle){
        address.street = bundle.getString("street");
        address.house = bundle.getString("house");
}

public void init(){
        btnSave.setOnClickListener(v->{
            getRouter().popCurrentController();
            Address address = new Address();
            address.street =  etStreet.getText().toString();
            address.house =  etHouse.getText().toString();
            CheckoutListener listener = (CheckoutListener) getTargetController();

            if (listener != null) {
                listener.setAddress(address);
            }
        });
}

Or is it better to save in SharedPreference?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-06-16
@terminator-light

There is no point in what you did. Nothing will be saved when recreating. Moreover, it will fall because you didn't make an empty constructor.
Arguments must be passed through the getArgs() bundle.
It is stupid to save in shared preferences, because this is a persistent storage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question