What is the proper way to restart hybrid service when app gets killed ?

Vaibhav Patil 11 Reputation points
2020-12-05T17:33:59.783+00:00

I've been developing chat app with Xamarin.Android, using hybrid service (Started + Binded) with STICKY. App basically using Signalr hubconnection inside service. Problem is some device vendors killing app service as app goes background. Giving one of following reason for service kill

-- app was idle
-- MIUILog AppServiceRestart rejected

I've also tried disabling battery optimizations and toggled AutoStart. Nothing works ! I know popular messenger apps are by default allowed by device vendors to run without issue.
Is there any way I can keep my service from getting killed or at least restart it as soon as it gets killed without having user to change system settings ?

Thanks !

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,347 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Alessandro Caliaro 4,186 Reputation points
    2020-12-05T18:19:21.577+00:00

    Have you tried with foreground service


  2. Alessandro Caliaro 4,186 Reputation points
    2020-12-06T08:11:45.35+00:00

    I think is the only possibility without to be a system app

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.