我想從一個活動發送2參數到另一個,但由於某種原因只有一個參數傳遞。會是什麼呢?意圖不通過我的數據
發送活動:
showActivity(OrderActivity.class, new Pair("CUSTOMER_ID", customerId), new Pair("CUSTOMER_TYPE", customerType));
接收活動:客戶ID是顯示0,但數據類型是得了
Bundle extras = getIntent().getExtras();
long customerId = extras.getLong("CUSTOMER_ID");
int customerType = extras.getInt("CUSTOMER_TYPE");
Log.d("===customer ", " id : " + customerId + " type : " + customerType);
的showActivity
看起來像這樣
protected void showActivity(Class<? extends BaseKaizenActivity> clazz, Pair<String, Object> ... parameters) {
Intent intent = new Intent(this, clazz);
if (parameters != null) {
for (Pair<String, Object> pair : parameters) {
if (pair.second instanceof Integer) {
intent.putExtra(pair.first, (Integer)pair.second);
}
else if (pair.second instanceof Parcelable) {
intent.putExtra(pair.first, (Parcelable)pair.second);
}
}
}
startActivity(intent);
}
發送發送活動中發送數據的完整代碼? – Praveenkumar
Y你不能簡單地使用getExtra和putExtra? –
你能發表showActivity()的細節嗎? – topxebec