This question has been asked before but I didnt find the answer helpful to my specific case.
I'm populating the ArrayList
parts from another activity
the first time I access the class but I keep losing the parts instance when I try to access it after the initial creation of it. Every time Task is called parts is empty and I'm not sure how to keep it filled with the details I want it filled with.
public class Task extends ListActivity{
private PartAdapter partsArrayAdapter;
ArrayList<Parts> parts ;//= new ArrayList<>()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null){
parts = (ArrayList<Parts>)savedInstanceState.getSerializable("parts");
}
else {
try {
// Get the Bundle Object
Bundle bundleObject = getIntent().getExtras();
// Get ArrayList Bundle
parts = (ArrayList<Parts>) bundleObject.getSerializable("parts");
} catch (Exception e) {
e.printStackTrace();
}
}
setContentView(R.layout.activity_parts_list);
partsArrayAdapter = new PartAdapter(this,parts);
setListAdapter(partsArrayAdapter);
}
@Override
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
outState.putSerializable("parts", parts);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
parts = (ArrayList<Parts>)savedInstanceState.getSerializable("parts");
}
}