I do Pedometer app for android. The principle of operation as follows: When you first launch the app, runs a service that runs in the foreground mode. Program prompts the user for Google account to login. If everything is fine then created GoogleApiClient object. Then in case of successful connection is created Fitness.SensorsApi in which I ask only in the number of steps of the system. Since I keep a not a lot of data, instead of a database I use SharedPreferences, and write new data there. If application is running, mainActivity connect to SharedPreferences every second to display the new values on the screen. All work is not bad. But sometimes, cease come on the number of steps. This may occur during the day sometimes it happens after the reset counters every day at 00:00 and sometimes a few days to work without problems. Helps only a complete restart the application.
And several times was that the data is not displayed on the screen, but the service has worked and recorded data. In this case, after application restart I immediately received the data for the entire period (hung screen). The service itself is 100% live, because I send a message in the log every 5 seconds. If someone is faced with a similar, please help, what could be the reason. Can GoogleApiClient loses connection or something else. How to track down an error? I will be very grateful.