I modified the BLE app so that it plots data that's coming from a sensor, shown below:
Now, when I close the app I want to be able to save the plot, so that next time when I open the app again, I can continue plot the graph instead of starting over.
I googled around and found this person recommending using Icepick library to save the app state. I tried his method but it didn't work, maybe I am using it wrong.
I added the @state variables at the top, added the @overide function and added the restoreInstanceState() function in my onCreate. Then I tried to store the last x and y value into the @state variables that I declared at the top of my code. Following is my code structure in DeviceControlActivity.java.
public class DeviceControlActivity extends Activity {
...
@State int saved_x_axies = 0;
@State int saved_y_axies = 0;
...
@Override public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.button_control);
Icepick.restoreInstanceState(this, savedInstanceState);
// double y, x;
Log.d("array","array ---> " + saved_y_axies);
...
}
...
private void displayData(TextView dataField, String data) {
if (data != null) {
dataField.setText(data);
if(dataField == ch1DataField) {
String[] parts = data.split(" ");
int ch1data = Integer.parseInt(parts[1]);
series0.appendData(new DataPoint(X_axies++, ch1data), true, 33);
saved_y_axies = ch1data;
saved_x_axies = X_axies;
}
}
}
}
Question 1, saved_y_axies gives me zero when I print it out using Log.d. From my code structure, is this how I am suppose to use the icepick library, if not can anyone tell me what I am doing wrong?
Question 2, can icepick library store int arrays? ultimately, I am thinking of storing all the sensor data into an array, when the app opens again, I am going to re-plot all the values to get the original graph back.
Thanks for the help!