2 回答

TA貢獻1776條經驗 獲得超12個贊
您可以將 Bundle 中的每個值分開,而不是在 Intent 中傳遞 HashMap。就像這樣:
Intent intent = new Intent(ViewStaffActivity.this,ProfileCRUD.class);
HashMap<String, String> hashMap = staffList.get(position);
Bundle extras = new Bundle();
extras.putString("NAME", hashmap.get("name"));
extras.putString("EMAIL", hashmap.get("email"));
extras.putString("USER_TYPE", hashmap.get("user_type"));
extras.putString("CREATED_AT", hashmap.get("created_at"));
intent.putExtras(extras);
startActivity(intent);
然后在另一個 Activity 的 onCreate() 中您將使用:
Bundle extras = getIntent().getExtras();
String name = extras.get("NAME");
...

TA貢獻1828條經驗 獲得超4個贊
您可以將 HashMap 轉換為 json 并通過 Intent 發送。使用以下代碼發送意圖:
String jsonStaff = (new Gson()).toJson(staffList.get(position));
intent.putExtra("jsonStaff", jsonStaff);
并專注于另一項活動,如下所示:
String jsonStaff = intent.getStringExtra("jsonStaff");
HashMap<String,String > dataStaff = (new Gson()).fromJson(jsonStaff, new HashMap<String,String >().getClass());
就這些。
添加回答
舉報