I am working on an Android app that needs to be connectedto some hardware and provide real time data to the end user through a linear chart. For that I am using MPAndroid library to show this Linear Chart inside a fragment.
This is what it look like
My problem is when I go to another view and comeback to my chart fragment, the chart lose all its value and goes back to the initial state. I tried putting my chart inisialization in OnCreate then in OnAttach, but it didn't work. My chart needs to keep those values until the end of the hour yet moving from screen to screen reset everything. This is my code:
c=Calendar.getInstance();
minute=c.get(Calendar.MINUTE);
hour=c.get(Calendar.HOUR_OF_DAY);
setXAxisValues( String.valueOf(hour));
setYAxisValues();
this code need to be called only when I enter the fragment for the first time and never be called again cauz it just set the chart.
EDIT
This is my code accordding to Piyush suggestion:
if (savedInstanceState!= null) {
yVals=savedInstanceState.getParcelableArrayList("savedList");
Log.e("TAG","********************************************saved instance*********************************************");
}
else {
c=Calendar.getInstance();
minute=c.get(Calendar.MINUTE);
hour=c.get(Calendar.HOUR_OF_DAY);
setXAxisValues( String.valueOf(hour));
Log.e("TAG","********************************************not saved*********************************************");
yVals=setYAxisValues();
}
final View view = inflater.inflate(R.layout.fragment_acceuil, container, false);