(Android) How to pass ArrayList<String> via intent and how to get it in the next activation?
UPD
Put in Intent:
public void get_masterList() { ... final String sferaOption; final ArrayList<String> midList = new ArrayList<>(); ... ... lvCatalog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView tvMid = (TextView) view.findViewById(R.id.tvMid); String mid = tvMid.getText().toString(); // Передаем id мастера в следующий Активити Intent intent = new Intent(catalog_activity.this, masterDetails2.class); intent.putExtra("mid", mid); intent.putExtra("sferaOption", sferaOption); intent.putExtra("midlist", midList); startActivity(intent); } }); } Checked through Debug - midList contains 3 items
We get in the following activation:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_master_details2); Toolbar toolbar = (Toolbar) findViewById(R.id.myToolBar); toolbar.setTitleTextColor(getResources().getColor(R.color.toolbar_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager()); pager.setAdapter(pagerAdapter); final String mid, sferaOption; ArrayList<String> midList; Bundle extras = getIntent().getExtras(); if (extras == null) { mid = null; sferaOption = null; midList = null; } else { mid = extras.getString("mid"); sferaOption = extras.getString("sferaOption"); } midList = (ArrayList<String>) getIntent().getSerializableExtra("midList"); Toast.makeText(this, midList.size(), Toast.LENGTH_SHORT).show(); Application is closed with an error, through Debug we see midList = null
putStringArrayListExtra()/getStringArrayListExtra()- Yura Ivanovmidlist, and look for themidList. The register matters. Use constants. - Yura Ivanov