I have nearly completed my application but I am still facing an issue.
I have a service which always runs in background, searching much in forum I used method startserviceat().
But I am not satisfied.
I tried using method startforeground with a notification icon but it was always cleared out whenever I cleaned using estaskmanager. I compared my service with whatsapp, it was never terminated except when I killed it manually...and there service uptime was much greater than mine even I started my service with whatsapp.
So can anyone provide a better solution I would really appreciate.
I just want to make a service always alive just like whatsapp messaging service.
There are other workarounds (which are not 100% reliable). You can create a static intent filter that listens to a relatively common message. This will allow you to restart your process if it was killed by a task manager.
It is not possible to create a process that cannot be killed by a task manager.
There are other workarounds (which are not 100% reliable). You can create a static intent filter that listens to a relatively common message. This will allow you to restart your process if it was killed by a task manager.
It is not possible to create a process that cannot be killed by a task manager.
The main problem that startserviceat method is not reliable as when I started thread the service was running and now its terminated.
Can you tell why process is terminated even if I use startforeground ?
I tried your sample and it was terminated where as other similar services were not terminated like uc download manager.
Whether the service is kept running or not depends on the task manager. Service.StartForeground is a standard Android API.
You can search Google. You will see that there are many similar discussions about task managers and services. There is no simple way to keep a service running if the user is using a task manager.
Whether the service is kept running or not depends on the task manager. Service.StartForeground is a standard Android API.
You can search Google. You will see that there are many similar discussions about task managers and services. There is no simple way to keep a service running if the user is using a task manager.
I haven't killed a process individually I just used optimizer option which kills all processes.My service was killed but whatsapp and ucdownload services we're running uninterrupted I just want to achieve that.
Take a look Android Service Tutorial
Running a service in its own process can help but is much more complicated. You can achieve a similar result by creating another application that is only responsible for the download.
I have a service that I restart in Service_Start with StartServiceAt......now+10000 (every 10 seconds)
I don't know if there are any drawbacks yet.
I have ONE feature that I don't want to persist across reboots. When rebooted, it should default to "off", but I don't have any way to tell if the Service_Create was invoked by a boot, or a StartServiceAt?
You can detect if the service was (auto) started at boot using this code:
B4X:
Sub Service_Start (StartingIntent As Intent)
If StartingIntent.Action="android.intent.action.BOOT_COMPLETED" Then
' service was auto started at boot
Else
' service was not auto started at boot
End If
End Sub
This gives you uptime of your application & shows the drawback of startserviceat....sometimes you will get uptime very low as application is closed & started again..variables are reseted !