1 | Tracker Update Site | http://121.243.11.246/NMCGITEST/webhome.aspx | |
Old site | http://nmcgpms.nic.in/StatewiseDetails.aspx | ||
2 | Total Projects | 95 | |
3 | Completed | 23 | |
4 | On going Projects | 40 | |
5 | Under tendering | 21 | |
6 | Tender to be floated | 11 | |
1 | Sewage Generation(2016) (MLD) | 2953 | |
2 | Existing capacity | 1429 | -1524 |
3 | Completed Projects | 172 | -1352 |
4 | Approved till now | 838 | -514 |
5 | Sanctioned by Apr 2018 | 3238 | |
6 | Sewage Generation(2035) (MLD) | 3603 |
Yogesh Kalwar
Sunday, May 13, 2018
Namami Gange Update
Sunday, September 24, 2017
Android - Job Scheduler
Job Scheduler
Reason to use
- For background task when apps in not foreground, we usually prefer Service to perform the task.
- But if your app targets API level 26 or higher, the system imposes restrictions on running background services when the app is not in foreground.
- If you have works that need to be done periodically, you need to use Alarm.
What is Job Scheduler
- JobScheduler is guaranteed to get your job done, but since it operates at the system level, it can also use several factors to intelligently schedule your background work to run with the jobs from other apps.
- You can minimize the resource usage using JobScheduler. And as of API 24, JobScheduler even considers memory pressure, which is a clear overall win for devices and their users.
- By introducing JobScheduler at the system level, we can focus on batching similar work requests together, which results in a noticeable improvement for both battery and memory.
The great advantage to JobScheduler is that it doesn’t perform work solely based on time, but rather based on conditions.
How to use it
- JobScheduler has 3 distinct part
- JobService
- The task you want to do will be defined in class extending JobService.
- This enables the system to perform your work for you, regardless of whether you app is active or not.
- The most convenient part of this structure is that you can write multiple JobServices, where each one defines a different task that should be performed at some point for your app.
- This helps you modularize your code base, and make code maintenance much simpler.
- Here we have 3 methods in JobService to look
- @override boolean onStartJob (JobParameters params):
- It is called by the system when your job is to be executed.
- If your task is short, you can write the logic in this method itself else you have to run that code in another thread, as JobService runs in mainThread.
- When job done then return false else if starting another thread to perform task in that, return true, letting the system know that you have a thread still running and it should hold on to your wakelock for a while longer.
- Return:
- True: to tell system that work is not finished and to hold wakelock for longer
- False: to tell system work done.
- void jobFinished():
- This method is not to override, and the system will not call it.
- You need to call this method once your service or thread has finished working on the job.
- If you have started another thread and returned true from onStartJob(), you will need to call this method from that thread when work is complete.
- This is how the system knows that it can safely release your wakelock. If you forget to all jobFinished(), your app is going to look pretty guilty in the battery stats lineup.
- jobFinished() requires two parameters: the current job, so that it knows which wakelock can be released, and a boolean indicating whether you had like to reschedule the job. If you passing true, this will kick off the JobScheduler’s exponential backoff logic for you.
- @override onStopJob (JobParameters params):
- This method is called by the system if the job is cancelled before being finished.
- This generally happens when your job conditions are no longer being met, such as when the device has been unplugged or if WiFi is no longer available.
- So use this method for any safety checks and clean up resource in response of half-finished job.
- Then return true if you had like the system to reschedule the job.
- Return:
- True: to tell system to reschedule job.
- False: to tell system not to reschedule job.
- JobInfo:
- This is the object which will define the conditions based on which system will invoke your job.
- To build the JobInfo object, you need two things every time, a job number and your JobService.
- Criterias:
- Network type (metered/unmetered)
- If your job requires network access, you must include this condition.
- You can specify a metered or unmetered network or any type of network.
- If you do not use this condition, system will assume that your job does not need network.
- Charging and Idle
- If your app needs to do work that is resource intensive, it is highly recommended that you wait until the device is plugged in and/or idle.
- ContentProvider updates
- As of API 24, you can use a content provider change as a trigger to perform some work.
- You will need to specify the trigger URI, which will be monitored with a ContentObserver.
- You can also specify a delay before your job is triggered, if you want to be certain that all changes propagate before your job is run.
- BackOff criteria
- You can specify your own backoff/retry policy.
- This defaults to an exponential policy, but if you set your own and then return true for rescheduling a job in onStopJob(), the system will employ your specified policy over the default.
- Minimum latency & override deadline
- If your job can not start for at least X amount of time, specify minimum latency.
- If all conditions met but your minimum latency has not elapsed, your job will be held.
- If your job can not be delayed past a specific time, specify override deadline.
- Even if all conditions have not been met, your job will be run by the deadline.
- You can check the result of isOverrideDeadlineExpired() to determine if you are in that case.
- Periodic
- If you have work that needs to be done regularly, you can set up a periodic job,
- This is a great alternative to a repeating alarm, because you sort it all once, schedule it, and the job will run once in each specified period.
- Persistence
- Any work that needs to be persisted across a reboot can be marked as such here. Once the device reboots, the job will be rescheduled according to your conditions.( RECEIVE_BOOT_COMPLETED permission needed in manifest).
- Extras
- If your job needs some information from your app to perform its work, you can pass along primitive data types as extras in the JobInfo.
- JobParameters:
- Contains the parameters used to configure/identify your job. You do not create this object yourself, instead it is handed in to your application by the System.
- JobScheduler has 3 steps to complete the task
- Create task by extending JobService class
- Create JobInfo object
- Initialise and schedule job by using JobScheduler.
Code
//Manifest entry
<service android:name=".DownloadJobSchedular.$DownloadService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
|
Next?
To be continued
Subscribe to:
Posts (Atom)