0

I have an Android app which reads the data from HR monitor, In that when user doing workout my app is able get the data. Even app goes in the background it is getting data.

The problem here is when we open 7 to 8 apps and comes to my app the app is going to onRestoreInstanceState. On that case i will not any data and total connection is lost. How to maintain that state to solve that issue.

Shankar
  • 269
  • 4
  • 17

1 Answers1

0

When you minimize or leave the Activity by opening next one it might be killed by the system. And onRestoreInstanceState is called when Activity is re-initialized. For getting data from a continuous connection you cannot relay on Activity. Because Activity may be destroyed or restarted when goes background. Consider using Service for this type of task. Service is designed for background and long running task when activity may not be alive. Use BroadcastReceiver to send data from Service to Activity. You can check this and this link for communicating between Service and Activity.

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50
  • I think my code is like that only. I written ble service and to get heartrate data I used broadcast. But after opening some 5-7 apps again coming to my app it's called reinitialized. My total workout data is lost. – Shankar Jul 10 '17 at 08:52
  • Then you can store data in some persistence storage. – Abu Yousuf Jul 10 '17 at 09:18