How to keep background refresh alive?

How is it possible to create a background refresh task, that stays alive?

I tried to trigger it with the page focus and the page mounted events and then stay in an endless delay loop. But the problem with these events is, that as soon as the phone is locked, these events will never be triggered again, unless the user interacts with the app.

So in the user experience this means the following. The first time I open the app, the app refreshes itself with new data from the server. Then I do something else and come back to the app. Now the app stays still and does not refresh itself anymore unless I click a button.