Coder Social home page Coder Social logo

googlearchive / android-jobscheduler Goto Github PK

View Code? Open in Web Editor NEW
770.0 58.0 282.0 994 KB

This sample has been deprecated/archived. Check this repo for related samples:

Home Page: https://github.com/android/background-tasks-samples

License: Apache License 2.0

Java 72.36% Kotlin 27.64%

android-jobscheduler's Introduction

Android JobScheduler Sample

This sample has been deprecated/archived meaning it's read-only and it's no longer actively maintained (more details on archiving can be found here).

Instead of JobScheduler, we recommend using the WorkManager. For a sample in that (and other related samples), check out the new github.com/android/background-tasks-samples repo. Thank you!

android-jobscheduler's People

Contributors

codingjeremy avatar google-automerger avatar tjohns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-jobscheduler's Issues

Cancelling schedule was not working

Steps to Reproduce

  1. Set the work duration for 10 seconds
  2. Click schedule job.
  3. click finish last task button at 3 seconds. onstop task event will get triggered.
  4. At 10th second also on stop task button will glow.
    This is because of calling sendMessage method within the run method of myjobservice class

after Android O background services cannot be started?

I'm not sure this example has been updated for Android O and beyond. How do you anticipate avoiding the following kind of exception?

Fatal Exception: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.tildejps.collagio/.compose.FetchVersionInfoService (has extras) }: app is in background uid UidRecord{7155f20 u0a86 CAC bg:+1m3s202ms idle change:idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1561)
at android.app.ContextImpl.startService(ContextImpl.java:1516)
at android.content.ContextWrapper.startService(ContextWrapper.java:657)
at xxx.onStart(MainActivity.kt:541)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1382)
at android.app.Activity.performStart(Activity.java:7151)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2949)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:194)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:157)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:72)
at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:55)
at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:4753)
at android.app.ActivityThread.relaunchAllActivities(ActivityThread.java:4336)
at android.app.ActivityThread.handleApplicationInfoChanged(ActivityThread.java:5195)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1789)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)

gradlew build failed

  1. I execute gradlew build in root directory,got the following error message:
    ======
    D:\Github\android-JobScheduler>gradlew build
    Starting a Gradle Daemon, 3 stopped Daemons could not be reused, use --status for details

Configure project :Application
Configuration 'compile' in project ':Application' is deprecated. Use 'implementation' instead.

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':Application'.

SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 4s

  1. If I load project in android studio, after update, sync ..., also failed.

PS:My studio version is 3.2, java version is 10.0.2

Periodic job not working

When I remove my app from the currently running apps list, then my job service does not show in adb shell dumpsys jobscheduler and it stops working periodically.

IDE project files checked in repo

  1. it is bad practices to check in your ide related files
  2. since you are using gradle, project can be easily recovered from build.gradle files.

Scheduling time out for .... jId: 2, in 18 s

2019-04-04 16:10:46.673 1126-5987/? D/JobServiceContext: Scheduling time out for '.core.service.NotifyJobService' jId: 2, in 18 s

2019-04-04 16:10:46.675 1126-1126/? D/JobServiceContext: handleServiceBound for fb9a063 #u0a938/2 com.icbc.im/.core.service.NotifyJobService

2019-04-04 16:10:46.675 1126-1126/? D/JobServiceContext: Scheduling time out for '.core.service.NotifyJobService' jId: 2, in 8 s

JobScheduler start job not triggered.

Hi I have been using JobScheduler since 3months. Haven't faced any issue until yesterday. It seem there is a behaviour change in the way it works. Whenever i use jobscheduler.schedule(jobinfo) it used to trigger immediately but right now it take 5mins or more to trigger the Job Service. Can I know why is this happening?

jobInfo = new JobInfo.Builder(JOB_SERVICE_LOCATION_PROBE, new ComponentName(getApplicationContext(), LocationJob.class))
                                        .setBackoffCriteria(BACKGROUND_JOB_BACK_OFF, JobInfo.BACKOFF_POLICY_EXPONENTIAL)
                                        .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                                        .setExtras(persistableBundle).build();

jobscheduler.schedule(jobInfo);

The 'onStartJob' method return a wrong result

In this sample, there are lines of code as below

    @Override
    public boolean onStartJob(JobParameters params) {
        // We don't do any real 'work' in this sample app. All we'll
        // do is track which jobs have landed on our service, and
        // update the UI accordingly.
        jobParamsMap.add(params);
        if (mActivity != null) {
            mActivity.onReceivedStartJob(params);
        }
        Log.i(TAG, "on start job: " + params.getJobId());
        return true;
    }

and return 'true' or return 'false' is based on the below words

True if your service needs to process the work (on a separate thread). False if
there's no more work to be done for this job.

In the 'onStartJob' you return 'true' and the sample does not process any time-wasted work, so I think you should return false here.

Start and stop job scheduling

I want to start and end scheduling through start and stop buttons. Once the scheduling works in the background, how can I stop it and vice versa? I didn't find the way to stop scheduler anywhere. cancelAll() only cancels the pending jobs but the scheduler does works again.

Main class

public class LiveTrack extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live_track);

        //start scheduling
        startLiveTrackBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                jobScheduler = (JobScheduler)getSystemService(JOB_SCHEDULER_SERVICE);
                ComponentName jobService =
                                new ComponentName(getPackageName(), MyJobService.class.getName());
                JobInfo jobInfo =
                                new JobInfo.Builder(MYJOBID, jobService)
                                        .setPeriodic(15 * 60 * 1000L)
                                        .setExtras(bundle)
                                        .build();
                int jobId = jobScheduler.schedule(jobInfo);

                if(jobScheduler.schedule(jobInfo)>0){
                }else{
                    Log.e("status","failed");
                }
            }
        }

        //stop scheduling
        endLiveTrackBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //how can I stop scheduling here until the start button is clicked again??  
                jobScheduler.cancelAll();
            }
        });
    }
}

JobService class

public class MyJobService extends JobService{
    @Override
    public boolean onStartJob(JobParameters jobParameters) {
        //some work
    }

    @Override
    public boolean onStopJob(JobParameters jobParameters) {
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.