0

I am developing a chat application in android . and need to keep service running even after exit from application . I am usin return START_STICKY; in onStartCommand() of my service . but because of limitation of services in android oreo , service will destroyed after seconds when exit from application. So far users lost new messages notifications. I can not use Fcm beacause of local networking and no access to internet. And I can not use ForegroundService . (because Of Employer's request to not showing any notification) . When I checked running service in android mobile setting , there are some apps that their service not killing like Es file explorer , Zapya , ... How they keep their service running without foreground service . And What should i do . Show in blow image , some apps services are running without any notification . service running

Hosein Kord
  • 187
  • 2
  • 15
  • If main functionality is periodic tasks, try converting it into [`JobIntentService`](https://developer.android.com/reference/android/support/v4/app/JobIntentService). – Pawel Jul 03 '18 at 09:53
  • No periodic task is not problem . We should keep connection alive with background service to show new messages notification to user .because of 15 minutes limitation of duration for scheduling May be user not receive new message in real time and he get messages with delay with this limitation. but if service keep running it will be in real time – Hosein Kord Jul 03 '18 at 17:20

1 Answers1

0

Based on the documentation:

The system distinguishes between foreground and background apps. An app is considered to be in the foreground if any of the following is true:

  • It has a visible activity, whether the activity is started or paused.
  • It has a foreground service.
  • Another foreground app is connected to the app, either by binding to one of its services or by making use of one of its content providers.

Reason Es FileExplorer can do could be (its just my opinion) following:

Es FileExplorer (is quite cheeky when it comes to taking advantage of some loop holes) have several content providers but one provider, FileProveders which is some how manages to have com.android.providers.settings connected to it. I guess this connection makes it foreground. They virtually have all the possible intent-filter registered for almost all the scheme. Anything you try to share or access, could trigger them some or the other way which keeps its process in use (you can just click on the details and you will find LocalCService of app running).

But for your app:

If you can't use FCM, ForegroundService and can't have visibility to user, then only option is to perform task periodically. You can use WorkManager. The only limitation is minimum duration for scheduling is 15 minutes. Refer to my answer for scheduling work with WorkManager and WorkManager vs Service for usage of WorkManager.

Sagar
  • 23,903
  • 4
  • 62
  • 62
  • Thanks Sagar , what about some app that their service keep running .Like Es File explorer or zapya . but my app service showing in running service from setting .but after a while that I exit from application service will destroyed and remove from running service list . how some app keep their service running without any notification. – Hosein Kord Jul 03 '18 at 16:51
  • I attached an image that shows some apps services are running in the background @Sagar - – Hosein Kord Jul 04 '18 at 06:00
  • Thanks @Sagar .Can I do something like Es File . How should I do .Can you explain more.Thanks. – Hosein Kord Jul 05 '18 at 04:03
  • @user2591041 You need to check how to implement the content provider for that. I haven't tried it by myself. – Sagar Jul 05 '18 at 04:06