0

I am using handler in activity to run task on every second. when app goes in background.I started service as a foreground which takes duration from local storage. after long time (When app is in background) this task that i started in activity seems not running as duration is not updating on User Interface, I am using Active-Android As ORM for saving data to local storage. please suggest any work around how to overcome such situation i will post the code if needed any help is appreciated.

Rohan Pawar
  • 1,875
  • 22
  • 40
Hardik Mehta
  • 867
  • 1
  • 12
  • 20
  • In which activity life cycle method (OnCreate/OnResume/OnPause) you called your handler? @Hardik Mehta – Nir Duan Aug 11 '16 at 08:03
  • @Nir Duan the architecture is such that there is seprate method which is called whenever user starts workout. i will post code if u want to see – Hardik Mehta Aug 11 '16 at 08:08

1 Answers1

0

I would highly recommend change your app's design, Activity not suppose to do any work that is not relevant to the UI attached to it.
In the current state the user create new thread from your activity and when the Android framework need additional resources (Can be hours after the activity is not visible anymore) it kills the activity and this is the reason why the UI doesn't seem to be updated.

My Solution-
Create a background serviceto perform the "update every X second" operation and bound your activity to it when it's visible.
1. How to create bound service
2. What are activity life-cycle

Nir Duan
  • 6,164
  • 4
  • 24
  • 38