kandi X-RAY | JobIntentService Summary
kandi X-RAY | JobIntentService Summary
JobIntentService
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Initializes the service
- Enqueue work in the given service
- Show the data from the main activity
- Set the receiver
- Display result
- Shows text
- Handle work
- Called when a receive result is received
JobIntentService Key Features
JobIntentService Examples and Code Snippets
Community Discussions
Trending Discussions on JobIntentService
QUESTION
I have a jobIntentService that create a file to add some text in it but I get the error /data/user/0/com.example.projet/files/log.txt (Is a directory)
. I don't know what I did wrong...
Here is my code :
ANSWER
Answered 2021-May-19 at 10:57With all the comment of you guys this work so there is the final code :
QUESTION
My application determines the speed limit by the user's location and tells the user if he has exceeded it. Starting with Android API level 30 and higher, Google has defined IntentService as deprecated and suggests using WorkManager or JobIntentService and also states that it is necessary to migrate from Firebase JobDispatcher to WorkManager. I see two ways to solve this problem:
- Start OneTimeWorkRequest and specify to restart this method periodically in this method while the application is running in the background.
- Run PeriodicWorkRequest with a minimum allowed interval of 15 minutes. In this method, run the JobIntentService method, which runs for up to about 10 minutes, but the method may not run or may be destroyed by the system before it is complete.
I'm worried about:
- potential memory leaks;
- potential problems with WorkManager or JobIntentService when going from foreground to background and vice versa
- the ability to use the MVVM pattern
ANSWER
Answered 2020-Dec-07 at 16:42I would prefer going with second option, it gives you more time between each rescheduling of the Worker
.
Regarding your concerns:
- Only possible leak is misconducting location callbacks. This can be easily tracked down, you shouldn't worry too much about it.
- Scheduled
Worker
are put in the database and are executed independently of the application. Which means, user-visibility of the application has no effect. In your case, I presume you want to cancel your scheduled work once the user resumes the application, that being said you can assign atag
to theWorker
and purge any scheduled or on-going once visible to the user. - I prefer to keep
Worker
s isolated from the MVVM and just inject Use cases/interactors in the worker and do execute the use case/query the interactor.WorkerManager
offers fine APIs to query theWorker
status, you might need to write common ground between your previous implementation and for API >= 30. Treat theWorker
as different execution container for your use case.
QUESTION
I have home screen widget, which has a simple AppWidgetProvider
and JobIntentService
, where I do all the work.
Problem is - it works kind of randomly. Sometimes it does, sometimes it doesnt - weirdest thing is, I can see in the log, that on each widget update enqueueWork
method of JobIntentService
is ALWAYS called, but onHandleWork
method only sometimes.
(I have found there is strong, though not 100% correlancy with battery optimization. If I turn of "Manage apps automatically", then it 99% works reliably. If it is turned on, its like flipping a coin. Sometimes it does, sometimes it doesnt. Best to ilustrate behavior would be this short simple video
This is my code (Widget provider):
...ANSWER
Answered 2020-Aug-31 at 07:34This is the same thing that is happening to me. What I've found out is that in the android documentation, it says:
When running as a pre-O service, the act of enqueueing work will generally start the service immediately, regardless of whether the device is dozing or in other conditions. When running as a Job, it will be subject to standard JobScheduler policies for a Job with a JobInfo.Builder.setOverrideDeadline(long) of 0: the job will not run while the device is dozing, it may get delayed more than a service if the device is under strong memory pressure with lots of demand to run jobs.
This means in Android O and above devices, it is not guaranteed that the jobIntentService starts immediately, but start with the delay depending on the device's condition. But, some phone manufacturers are deliberately canceling the job for better battery life (Like OnePlus). So the job is never called.
The workaround that I used is to create a LOW_IMPORTANCE foreground service and call it using:
QUESTION
I want to get a List from my Room-Database for a notification, where I use a BroadcastReceiver and a JobIntentService.
Because I don't have a context I can't obtain the ViewModel. So I need another way to get the data.
In this article I read something about a Singleton. But I don't know how to get the data now from the database with the Singleton.
...ANSWER
Answered 2020-Jul-03 at 13:45I solved the issue like this: I saved the important data I need for the notification in Shared Preferences. In the BroadcastReceiver I can retrieve the data from the Shared Preferences and use it in the notification.
QUESTION
Following FetchAddressIntentService
implementation with IntentService
(in kotlin):
ANSWER
Answered 2020-Jun-03 at 08:14class FetchAddressIntentService : JobIntentService() {
// This method is called when service starts instead of onHandleIntent
override fun onHandleWork(intent: Intent) {
onHandleIntent(intent)
}
// remove override and make onHandleIntent private.
private fun onHandleIntent(intent: Intent?) {}
// convenient method for starting the service.
companion object {
fun enqueueWork(context: Context, intent: Intent) {
enqueueWork(context, FetchAddressIntentService::class.java, 1, intent)
}
}
}
QUESTION
I have a JobIntentService which is supposed to do an API call and do a broadcast once the result is available.
I am using a Coroutine to do the network call using Retrofit. However, if I do sendBroadcast within the CoroutineScope , it does not trigger the BroadcastReceiver
This is my service code -
MyService.kt
...ANSWER
Answered 2020-May-22 at 17:36You should not use a coroutine here. The onHandleWork
method is called on a background thread, and returning from this method signals the work is done and the service can be terminated.
As you are launching a coroutine with launch
, the onHandleWork
returns immediately and your service terminates.
You should call your network API directly and not in a coroutine because JobIntentService
is designed to work this way already.
QUESTION
I use Firebase high priority push notifications to trigger Panic alarms in Android devices. For first few tries of push, immediately push notifications arrives and it works great. But when i keep triggering push notifications after certain amount of time slowly delay keeps increasing.
I want it to trigger immediately as it is Panic situation.
I also followed the documentation which read:
High priority: FCM attempts to deliver high priority messages immediately, allowing the FCM service to wake a sleeping device when necessary and to run some limited processing (including very limited network access). High priority messages generally should result in user interaction with your app or its notifications. If FCM detects a pattern in which they don't, your messages may be de-prioritized. Android P introduced app standby buckets which limit the number of FCM high priority messages you can send to your app that don't result in the user using your app or viewing a notification. If, in response to a high priority message, a notification is displayed in a way that is visible to the user, then your app standby bucket quota will not be consumed by that message.
Because a small portion of the Android mobile population are on high latency networks, avoid opening a connection to your servers before displaying a notification. Calling back to the server before the end of the allowed processing time may be risky for users on high latency networks. Instead, include the notification content in the FCM message and display it immediately. If you need to sync for additional in-app content on Android, you can schedule an FJD job or a JobIntentService to handle that in the background.
How can I make sure high priority messages are triggered as soon as possible? May be within a minute in all cases.
...ANSWER
Answered 2020-May-21 at 19:32If FCM detects a pattern in which they don't, your messages may be de-prioritized. Android P introduced app standby buckets which limit the number of FCM high priority messages you can send to your app that don't result in the user using your app or viewing a notification. If, in response to a high priority message, a notification is displayed in a way that is visible to the user, then your app standby bucket quota will not be consumed by that message.
QUESTION
I've custom JobIntentService witn static method enqueueWork.
...ANSWER
Answered 2020-May-14 at 04:56Nothing incorrectly. Unfortunately, JobIntentService will not run immediately on Android 8.0 and higher.
QUESTION
I'm working on an android app for tracking daily app usage. The idea is that a user can set daily time limit for any app and a notification will appear within at most 2 minutes after the limit is exceeded. (The reason for delay: I've created an alarm system using AlarmManager class that will go off every minute to run a JobIntentService which will check whether limit for any app is exceeded)
I've used queryEvents method of UsageStatsManager class to count app usage time.
Here's my code for counting app usage time (I've followed How to use queryEvents):
...ANSWER
Answered 2020-May-11 at 09:46I've solved the issue.
Adding difference of current time and timestamp of current running app going foreground does the trick.
I just added the following code before the return statement:
QUESTION
What have I done so far...
I am using Tasks.await
blocking mechanism for firebase calls in worker threads for avoiding callbacks.
I am using a worker thread (JobIntentService) for some initialization progress. JobIntentService starts when app opens and runs only once. below is my worker thread code
...ANSWER
Answered 2020-Mar-30 at 14:30I contacted Firebase Support for this issue
They said
This happens if the connection of the device user had an issue as our SDK tried to call the fetch of data, and it would cause “The client had an error while calling the backend!” error. With that, it looks like you’re doing the right thing on validating the connectivity on your recent updates before you fetch the remote config data. You can check our implementation here that you could visualize our call that would trigger this issue.
You could use the Android network debugger to simulate the network calls, so you could catch your handling mechanism to ensure that your actual device has a proper connectivity on doing the fetch.
So the problem might be the network connectivity of the device. I check the network connectivity in recent updates. but still I am getting this error in some devices. The reason may be the the poor quality of the Internet connection at the moment of the devices (@Tash Pemhiwa suggested in comment)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install JobIntentService
You can use JobIntentService like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the JobIntentService component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page