Hello,
Welcome to our Microsoft Q&A platform!
Is it possible to make the Button function when the app is not running
Starting in Android 8.0 (API level 26), an Android application no longer have the ability to run freely in the background. Try using the foreground sevice by starting a foregroud notification to keep the widget working even when it is closed.
[Service(Enabled = true)]
public class MyService : Service
{
private Handler handler;
private Action runnable;
private bool isStarted;
...
public override void OnCreate()
{
base.OnCreate();
handler = new Handler();
//here is what you want to do always, i just want to push a notification every 5 seconds here
runnable = new Action(() =>
{
if (isStarted)
{
DispatchNotification();
handler.PostDelayed(runnable, 5000);
}
});
}
...
}
Similar issue: https://stackoverflow.com/questions/60028587/background-service-with-isolated-process-in-xamarin-forms/60032046
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.