I am writing an alarm based app for Android, the app consist of 2 activities:
MainActivity
- which the user can set the alarm parameters.
DataPage
- which monitors the relevant data and display to the user, if data is out of limit, an alarm is triggered (using m.player).
The problem is, when the user navigates back from the DataPage, it returns to the MainActivity of course, but the DataPage process is still running on the background, this is a problem since if the user set the alarm again, a new DataPage is running and now there are 2 alarms set (without the option the cancel the first one).
So, how do I stop the activity and its Java class process on back button pressed?
I overrode the onBackPressed() method like this -
finish();
Intent intent = new Intent(this, DataPage.class);
stopService(intent);