I want to pass an ArrayList<String>
and an ArrayList<Boolean>
to my next activity, but whatever I try, it always seems to overwrite my first ArrayList with my second. Even if I use a boolean array in stead of an ArrayList, the same problem occurs. The KEY's are different and the values as well. I tried many things already (can't remember all of it), including Bundles, but the same keeps happening. What am I doing wrong?
In both cases (and many others), data comes back null.
EDIT: Cleaned up code after a night's sleep, as I noticed there were indeed some mistakes in it. Also, these are 2 ways that I tried to do it, but neither work.
In activity 1:
boolean [] checksDataOut;
private ArrayList<String> data = new ArrayList();
intent.putStringArrayListExtra(EXTRA_TODEVICES, data);
intent.putExtra(EXTRA_TO_DEVICES, checksDataOut);
startActivity(intent);
In Activity 2
public class DevicesInfo extends AppCompatActivity {
public ArrayList<String> data = new ArrayList();
public boolean [] checksDataIn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_devices_info);
Intent intent = getIntent();
data = intent.getStringArrayListExtra(EXTRA_TODEVICES);
checksDataIn = intent.getBooleanArrayExtra(EXTRA_TO_DEVICES);
}
}
In activity 1:
private ArrayList<String> data = new ArrayList();
boolean [] checksDataOut;
Bundle extrasOut = new Bundle();
extrasOut.putStringArrayList(EXTRA_TODEVICES, data);
extrasOut.putBooleanArray(EXTRA_TO_DEVICES, checksDataOut);
intent.putExtras(extrasOut);
startActivity(intent);
In activity 2:
public class DevicesInfo extends AppCompatActivity {
public ArrayList<String> data = new ArrayList();
public ArrayList<Boolean> checksData = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_devices_info);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
data = bundle.getStringArrayList(EXTRA_TODEVICES);
checksData = (ArrayList<Boolean>) bundle.get(EXTRA_TO_DEVICES);
}
}