我有一個關於java/android Studio中的類之間進行通信的問題。Android之間的通信
我有一個信息傳遞到海誓山盟這樣四類:
MainActivity{
Intent intent = new Intent (this, Main2Activity.class);
intent.putStringArrayListExtra("addressesList", addressList);
startActivity(intent);
}
Main2Activity{
private ArrayList addressList = new ArrayList();
addressList = getIntent().getStringArrayListExtra("addressesList");
Calculate calulate = new Calculate(this);
calulate.getTravelInformation();
}
Calculate{
private ApiCall apiCall = new ApiCall(this);
private ArrayList addressesList = new ArrayList();
private Main2Activity activity;
public Calculate (Main2Activity a){
activity = a;
addressesList = activity.addressList;
}
protected void doSomething(){
}
}
ApiCall{
private Calculate calculate;
protected ApiCall(Calculate a){
calculate = a;
}
calculate.doSomething();
}
所以我的問題是,是否有這樣做的更好的方法,是沒有任何理由爲什麼我不應該做這樣的?
非常感謝您的幫助。