I have the activity1 that extends fragment. Here there is an ArrayList (FinalListToSend) that I want to pass to the other activity2
//ACTIVITY1
public class Page1Activity extends Fragment {
ArrayList<String> FinalListToSend;
public ArrayList<String> getList() {
return FinalListToSend;
}
public void setList(ArrayList<String> FinalListToSend) {
this.FinalListToSend = FinalListToSend;
}
public static Page1Activity newInstance() {
Page1Activity fragment = new Page1Activity();
return fragment;
}
public Page1Activity() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_page1, container, false);
return rootView;
}
}
I want to get the ArrayList in a second activity2
//ACTIVITY2
public static Page2Activity newInstance() {
Page2Activity fragment = new Page2Activity();
return fragment;
}
public Page2Activity() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.activity_page2, container, false);
Page1Activity page1= new Page1Activity();
ArrayList<String> ListToSave = new ArrayList<String>();
ListToSave=new ArrayList<String>(page1.FinalListToSend);
return rootView;
}}
I use view pager for this two activities. I use this code and when I debug the FinalListToSend gets the items correctly when I am in Page1Activity, but when I press the button on PageActivity the FinalListToSend gets null.Any idea to get the array from the second activity?