我在ActivityA中創建了一個ArrayList,我想將它傳遞給ActivityB。從一個Intent傳遞ArrayList <Object>到另一個
ActivityA:
ArrayList<CardDetails> cardDetailsToPass = new ArrayList<>();
if (v.getId() == balance.getId()){
for(CardDetails cardDetails : cardDetailsArrayList){
int clientID = cardDetails.getClientID();
int cardID = cardDetails.getCardID();
int cardNo = cardDetails.getCardNo();
int balance = cardDetails.getCardBalance();
int availableBalance = cardDetails.getCardAvailableBalance();
int limit = cardDetails.getCardLimit();
int expDate = cardDetails.getExpDate();
String status = cardDetails.getStatus();
cardDetailsToPass.add(new CardDetails(clientID,cardID,cardNo,balance,availableBalance,limit,expDate,status));
Log.d("Adapter","clientID "+cardDetails.getClientID());
Log.d("Adapter","cardID "+cardDetails.getCardID());
Log.d("Adapter","cardNo "+cardDetails.getCardNo());
Log.d("Adapter","cardBalance "+cardDetails.getCardBalance());
Log.d("Adapter","cardAvailableBalance "+cardDetails.getCardAvailableBalance());
Log.d("Adapter","cardLimit "+cardDetails.getCardLimit());
Log.d("Adapter","cardExpDate "+cardDetails.getExpDate());
Log.d("Adapter","cardStatus "+cardDetails.getStatus());
}
Intent intent = new Intent(context, CardStatementActivity.class);
intent.putExtra("cardDetailsToPass",cardDetailsToPass);
context.startActivity(intent);
ActivityB:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_statement);
Bundle extras = getIntent().getExtras();
if(extras != null){
//get the ArrayList here
}
}
我已經試過這樣做,但沒有成功的一種方法。傳遞對象的ArrayList是否需要別的東西?
謝謝@扎基爾它像一個魅力工作! – pavlos