I\'ve been struggling with this for 2 weeks now.
I\'m developing an app that controls call duration.
I receive a braodcast where I start a foreground service to
Edit:
If you have the same issue please check Power Saving Options in your phone settings if your phone has this feature it will kill your app after the screen is off and will not allow it to work in background.
Original answer: After a lot of search I solved it myself
it turned out that my app was power-intensive as shown in the picture below
Hence, android was force stopping it after 5 minutes when there is no activity on the screen to save power.
I solved power consumption issues and everything became OK.