-2

After Android 5.0 there is some restriction to use android service (to perform background operation while application force closed).i want to perform some operation after app was force closed.

In that situation shall i go with job scheduler to perform that task OR is there any other way to start service(After android 5.0 in some times app crashed while start service in android 6.0)

Give your opinion with valid reason ,thanks

MurugananthamS
  • 2,395
  • 4
  • 20
  • 49
  • Please check my answer here: https://stackoverflow.com/questions/55571182/service-stops-working-when-app-gets-closed/55571560#55571560 Hope it help :) – Ajay Mehta Apr 09 '19 at 05:23
  • you were right if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ContextCompat.startForegroundService(context, new Intent(context, YourService.class)); ,in my application start forgroundService also get grashed ,thats why i prefare job secheduler – MurugananthamS Apr 09 '19 at 05:25
  • thanks for respond my question @Ajay-Rlogical – MurugananthamS Apr 09 '19 at 05:26
  • Any Suggestions – MurugananthamS Apr 09 '19 at 06:28
  • If start forground crashing in your case then please share crash log is possible. – Ajay Mehta Apr 09 '19 at 06:30
  • 2019-04-09 12:24:59.213 20301-20301/com.package.app E/AndroidRuntime: FATAL EXCEPTION: main Process:com.package.app, PID: 20301 android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() this was i got from logcat @Ajay-Rlogical – MurugananthamS Apr 09 '19 at 06:57
  • Have you added permission in AndroidManifest.xml? – Ajay Mehta Apr 09 '19 at 07:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/191509/discussion-between-murugananthams-and-ajay-rlogical). – MurugananthamS Apr 09 '19 at 07:25

1 Answers1

1

Choosing the right solution for your work


  • Can the work be deferred, or does it need to happen right away?

    For example, if you need to fetch some data from the network in response to the user clicking a button, that work must be done right away. However, if you want to upload your logs to the server, that work can be deferred without affecting your app’s performance or user expectations.

  • Is the work dependent on system conditions?

    You might want your job to run only when the device meets certain conditions, such as being connected to power, having internet connectivity, and so on. For example, your app might periodically need to compress its stored data. To avoid affecting the user, you would want this job to happen only when the device is charging and idle.

  • Does the job need to run at a precise time?

    A calendar app might let a user set up a reminder for an event at a specific time. The user expects to see the reminder notification at the correct time. In other cases, the app may not care precisely when the job runs. The app might have general requirements—like, "Job A must run first, then Job B, then Job C"—but it doesn't require jobs to run at a specific time.

Choosing the right solution for your work


Read more at Choosing the right solution for your work

Community
  • 1
  • 1
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • i can perform that task using job scheduler as well as Service,here my problem is before android 5.0 service will working fine but after 5.0 it will crash while start service alternatively we can use job scheduler to perform that task ,thats why i am asking is there any other option to start service after android 5.0 or else we can go with job scheduler@Pankaj Kumar – MurugananthamS Apr 09 '19 at 06:34