0

I want to implement voice actions, "start running" and "stop running".

"Start running" works fine, but "stop running" doesn't work.

My app has one activity with several fragments. When I speak "stop running", the activity is destroyed and created. My workout data is lost.

  • setRetainInstance(true) has no effect.
  • Change launchMode to singleTask/singleTop/singleInstance has no effect.
  • I saved workout data in onSaveInstanceState(), but it's lost when a new activity is created.

Is there any other way?

kazhik
  • 556
  • 1
  • 5
  • 7

1 Answers1

-1

I'm not sure if this is too obvious, but have you considered using SharedPreferences?

To save data:

sPref = getPreferences(MODE_PRIVATE);
testNum = 2;
SharedPreferences.Editor editor = sPref.edit();
editor.putInt("testName", testNum);
editor.commit();

To get data:

sPref = getPreferences(MODE_PRIVATE);
int retrievedTestNum = sPref.getInt("testName",-1);
System.out.println("The number you saved was " + retrievedTestNum + "!");

You can also save data in arrays and store it in the SharePreferences.

If this is too simple for you, you can grab a mySQL database, which is much more robust.

Alex K
  • 8,269
  • 9
  • 39
  • 57