mercredi 6 mai 2015

Custom Listener using Intent

I have created a custom listener using the following code in EditTransactionActivity:

private OnTransactionUpdateListener mTranUpdateListener;


public interface OnTransactionUpdateListener {
    public void transactionUpdated(Tran tran);
}

public void setTransactionUpdateListener(OnTransactionUpdateListener listener) {
    this.mTranUpdateListener = listener;
}

I call the method using:

mTranUpdateListener.transactionUpdated(mTransaction);

In TransactionDetailActivity I have implemented the class with the following method:

@Override
public void transactionUpdated(Tran tran) {
    this.mTransaction = tran;
}

The problem I have is that the listener has not been set, since I am loading EditTransactionActivity using an Intent, how do I set the listener? I have no instance of the object to set.

Intent intent = new Intent(getApplicationContext(),
                EditTransactionActivity.class);
Bundle bundle = new Bundle(
bundle.putSerializable("transaction_key", mTransaction);
intent.putExtras(bundle);
startActivity(intent);

Aucun commentaire:

Enregistrer un commentaire