应用无法预测的行为

时间:2016-01-14 12:37:02

标签: android android-asynctask android-sqlite android-jobscheduler

我正在创建一个使用Async Task和JobShceduler并使用SQlite的应用程序,问题是当我在模拟器Api 23中运行应用程序时,如果我在SAmsung Grand Prime中运行相同的应用程序,它不会崩溃应用程序Kitkat崩溃。我是初学者,我已经没有选择如何解决这个问题,我非常感谢你的帮助.. 这是模拟器Log cat。

01-14 15:13:04.777 27970-27970/comeagain.materialdesign D/DOm: onCreateHolder Called
01-14 15:13:04.777 27970-27970/comeagain.materialdesign D/DOm: onBindViewHolder Called2
01-14 15:13:04.779 27970-27970/comeagain.materialdesign D/DOm: onCreateHolder Called
01-14 15:13:04.779 27970-27970/comeagain.materialdesign D/DOm: onBindViewHolder Called3
01-14 15:13:04.781 27970-27970/comeagain.materialdesign D/DOm: onCreateHolder Called
01-14 15:13:04.781 27970-27970/comeagain.materialdesign D/DOm: onBindViewHolder Called4
01-14 15:13:04.781 27970-27970/comeagain.materialdesign D/DOm: onCreateHolder Called
01-14 15:13:04.781 27970-27970/comeagain.materialdesign D/DOm: onBindViewHolder Called5
01-14 15:13:04.793 27970-27970/comeagain.materialdesign D/DOm: onCreateHolder Called
01-14 15:13:04.793 27970-27970/comeagain.materialdesign D/DOm: onBindViewHolder Called6
01-14 15:13:04.795 27970-27970/comeagain.materialdesign D/DOm: onCreateHolder Called
01-14 15:13:04.795 27970-27970/comeagain.materialdesign D/DOm: onBindViewHolder Called7
01-14 15:13:04.796 27970-27970/comeagain.materialdesign D/DOm: onCreateHolder Called
01-14 15:13:04.796 27970-27970/comeagain.materialdesign D/DOm: onBindViewHolder Called8
01-14 15:13:04.797 27970-27970/comeagain.materialdesign W/View: requestLayout() improperly called by android.support.v7.widget.AppCompatImageView{d0504a8 V.ED..... ......ID 0,0-0,0 #7f0b0095 app:id/selector} during layout: running second layout pass
01-14 15:13:04.797 27970-27970/comeagain.materialdesign W/View: requestLayout() improperly called by android.support.v7.widget.AppCompatImageView{47e5bc1 V.ED..... ......I. 0,0-0,0 #7f0b0095 app:id/selector} during layout: running second layout pass
01-14 15:13:04.797 27970-27970/comeagain.materialdesign W/View: requestLayout() improperly called by android.support.v7.widget.AppCompatImageView{2080f66 V.ED..... ......I. 0,0-0,0 #7f0b0095 app:id/selector} during layout: running second layout pass
01-14 15:13:05.446 27970-27970/comeagain.materialdesign I/Choreographer: Skipped 36 frames!  The application may be doing too much work on its main thread.
01-14 15:13:05.745 27970-27977/comeagain.materialdesign W/art: Suspending all threads took: 261.944ms
01-14 15:13:49.940 27970-28012/comeagain.materialdesign W/OpenGLRenderer: Incorrectly called buildLayer on View: View, destroying layer...
01-14 15:15:06.207 27970-27977/comeagain.materialdesign W/art: Suspending all threads took: 14.666ms
01-14 15:18:54.169 27970-27977/comeagain.materialdesign W/art: Suspending all threads took: 11.745ms
01-14 15:21:42.759 27970-28012/comeagain.materialdesign W/OpenGLRenderer: Incorrectly called buildLayer on View: View, destroying layer...

这是Real device Logcat

    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.keySet
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.newInstance
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve new-instance 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x22 at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.newInstance
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve new-instance 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x22 at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.newInstance
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve new-instance 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x22 at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putAll
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putDouble
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putDoubleArray
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putInt
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putIntArray
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.495 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putLong
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putLongArray
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putPersistableBundle
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putString
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.putStringArray
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign I/dalvikvm: Could not find method android.os.Parcel.readPersistableBundle, referenced from method me.tatarka.support.os.PersistableBundleCompat.read
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve virtual method 1259: Landroid/os/Parcel;.readPersistableBundle ()Landroid/os/PersistableBundle;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.remove
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.size
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method me.tatarka.support.os.PersistableBundleCompat.write
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve check-cast 235 (Landroid/os/PersistableBundle;) in Lme/tatarka/support/os/PersistableBundleCompat;
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x1f at 0x0006
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: DexOpt: unable to opt direct call 0x0506 at 0x08 in Lme/tatarka/support/os/PersistableBundleCompat;.newInstance
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: DexOpt: unable to opt direct call 0x0507 at 0x08 in Lme/tatarka/support/os/PersistableBundleCompat;.newInstance
    01-14 15:24:05.505 4958-4958/comeagain.materialdesign D/dalvikvm: DexOpt: unable to opt direct call 0x0508 at 0x0a in Lme/tatarka/support/os/PersistableBundleCompat;.newInstance
    01-14 15:24:05.625 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/job/JobParameters;)
    01-14 15:24:05.625 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/job/JobParameters;)
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/job/JobParameters;)
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/job/JobParameters;)
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/job/JobParameters;)
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/job/JobParameters;)
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign I/dalvikvm: Could not find method android.app.job.JobParameters.getJobId, referenced from method me.tatarka.support.internal.IJobServiceCompat.convertFromJobParameters
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to resolve virtual method 300: Landroid/app/job/JobParameters;.getJobId ()I
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign D/dalvikvm: VFY: replacing opcode 0x6e at 0x0007
    01-14 15:24:05.635 4958-4958/comeagain.materialdesign W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/app/job/JobParameters;)
    01-14 15:24:05.705 4958-4999/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 3567K, 32% free 11273K/16444K, paused 25ms, total 25ms
    01-14 15:24:06.725 4958-5685/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:06 EAT 2016
    01-14 15:24:06.855 4958-4997/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 973K, 29% free 11832K/16444K, paused 19ms, total 19ms
    01-14 15:24:07.815 4958-5703/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:07 EAT 2016
    01-14 15:24:08.305 4958-4998/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 1009K, 24% free 12501K/16444K, paused 30ms, total 30ms
    01-14 15:24:08.635 4958-5724/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:08 EAT 2016
    01-14 15:24:09.545 4958-5001/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 1105K, 20% free 13178K/16444K, paused 31ms, total 31ms
    01-14 15:24:09.655 4958-5738/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:09 EAT 2016
    01-14 15:24:10.735 4958-4999/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 1477K, 19% free 13875K/16956K, paused 29ms, total 29ms
    01-14 15:24:10.855 4958-5002/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:10 EAT 2016
    01-14 15:24:12.055 4958-5685/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:12 EAT 2016
    01-14 15:24:12.965 4958-4998/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 2873K, 26% free 13311K/17800K, paused 39ms, total 39ms
    01-14 15:24:13.075 4958-5703/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:13 EAT 2016
    01-14 15:24:14.005 4958-5001/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 1627K, 22% free 13904K/17800K, paused 28ms, total 29ms
    01-14 15:24:14.095 4958-5724/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:14 EAT 2016
    01-14 15:24:15.195 4958-5738/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:15 EAT 2016
    01-14 15:24:16.275 4958-5000/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 2868K, 26% free 13342K/17900K, paused 45ms, total 45ms
    01-14 15:24:16.395 4958-5002/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:16 EAT 2016
    01-14 15:24:17.405 4958-4998/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 1613K, 23% free 13959K/17900K, paused 34ms, total 34ms
    01-14 15:24:17.495 4958-5685/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:17 EAT 2016
    01-14 15:24:17.715 4958-4958/comeagain.materialdesign E/ActivityThread: Service me.tatarka.support.internal.job.JobSchedulerService has leaked ServiceConnection me.tatarka.support.internal.job.JobSchedulerService$JobServiceConnection@425ae1c0 that was originally bound here
                                                                            android.app.ServiceConnectionLeaked: Service me.tatarka.support.internal.job.JobSchedulerService has leaked ServiceConnection me.tatarka.support.internal.job.JobSchedulerService$JobServiceConnection@425ae1c0 that was originally bound here
                                                                                at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:970)
                                                                                at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:864)
                                                                                at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1706)
                                                                                at android.app.ContextImpl.bindService(ContextImpl.java:1689)
                                                                                at android.content.ContextWrapper.bindService(ContextWrapper.java:524)
                                                                                at me.tatarka.support.internal.job.JobSchedulerService.handleStartJob(JobSchedulerService.java:82)
                                                                                at me.tatarka.support.internal.job.JobSchedulerService.access$400(JobSchedulerService.java:29)
                                                                                at me.tatarka.support.internal.job.JobSchedulerService$1.handleMessage(JobSchedulerService.java:310)
                                                                                at me.tatarka.support.internal.job.JobSchedulerService.onStartCommand(JobSchedulerService.java:46)
                                                                                at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2846)
                                                                                at android.app.ActivityThread.access$2100(ActivityThread.java:155)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:136)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5426)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
                                                                                at dalvik.system.NativeStart.main(Native Method)
    01-14 15:24:18.445 4958-5703/comeagain.materialdesign D/VIVZ: inserting entries 49Thu Jan 14 15:24:18 EAT 2016
    01-14 15:24:18.475 4958-4958/comeagain.materialdesign D/AndroidRuntime: Shutting down VM
    01-14 15:24:18.485 4958-4958/comeagain.materialdesign W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41725d58)
    01-14 15:24:18.485 4958-4958/comeagain.materialdesign E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: comeagain.materialdesign, PID: 4958
                                                                            java.lang.IllegalArgumentException: Service not registered: me.tatarka.support.internal.job.JobSchedulerService$JobServiceConnection@4263df10
                                                                                at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:922)
                                                                                at android.app.ContextImpl.unbindService(ContextImpl.java:1740)
                                                                                at android.content.ContextWrapper.unbindService(ContextWrapper.java:536)
                                                                                at me.tatarka.support.internal.job.JobSchedulerService.finishJob(JobSchedulerService.java:212)
                                                                                at me.tatarka.support.internal.job.JobSchedulerService.access$000(JobSchedulerService.java:29)
                                                                                at me.tatarka.support.internal.job.JobSchedulerService$JobServiceConnection$1.jobFinished(JobSchedulerService.java:123)
                                                                                at me.tatarka.support.job.JobService$JobHandler.handleMessage(JobService.java:122)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:136)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5426)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
                                                                                at dalvik.system.NativeStart.main(Native Method)
    01-14 15:24:19.125 4958-4999/comeagain.materialdesign D/dalvikvm: GC_FOR_ALLOC freed 2811K, 26% free 13358K/17900K, paused 35ms, total 35ms

ActivityMain

        private JobScheduler mJobScheduler;
    private static final long POLL_FREQUENCY = 28800000;

    private static final String TAG_SORT_NAME = "sortName";
    private static final String TAG_SORT_DATE = "sortDate";
    private static final String TAG_SORT_RATINGS = "sortRatings";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mJobScheduler = JobScheduler.getInstance(this);



        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                constructJob();
            }
        }, 30000);

        toolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
/*
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
*/
        NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment)
                getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);
        mPager = (ViewPager) findViewById(R.id.pager);

        mTabHost = (MaterialTabHost) findViewById(R.id.materialTabHost);
        adapter = new ViewPagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(adapter);
        mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                mTabHost.setSelectedNavigationItem(position);
            }
        });
        for (int i = 0; i < adapter.getCount(); i++) {
            mTabHost.addTab(
                    mTabHost.newTab()
                            .setIcon(adapter.getIcon(i))
                            .setTabListener(this)
            );
        }
        buildFAB();
    }
public void constructJob(){
    JobInfo.Builder builder=new JobInfo.Builder(JOB_ID, new ComponentName(this, MyService.class));
    builder.setPeriodic(POLL_FREQUENCY)
           .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
            .setPersisted(true);
    mJobScheduler.schedule(builder.build());

    }

请求者类

    public static JSONObject sendRequestBoxOfficeMovies(RequestQueue requestQueue, String url) {
        JSONObject response=null;
        RequestFuture<JSONObject> requestFuture=RequestFuture.newFuture();
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET,
                url,
                (String)null, requestFuture, requestFuture);
        requestQueue.add(request);
        try {
            response=requestFuture.get(30000, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            L.m(e + "");
        } catch (ExecutionException e) {
            L.m(e + "");
        } catch (TimeoutException e) {
            L.m(e + "");
        }
        return response;
    }

}

TaskLoad

public class TaskLoadMoviesBoxOffice extends AsyncTask<Void, Void, ArrayList<Movie>> {
private BoxOfficeLoadedListener myComponent;
private VolleySingleton volleySingleton;
private RequestQueue requestQueue;

public TaskLoadMoviesBoxOffice(BoxOfficeLoadedListener myComponent) {
    this.myComponent = myComponent;
    volleySingleton = VolleySingleton.getsInstance();
    requestQueue = volleySingleton.getmRequestQueue();
}

@Override
protected ArrayList<Movie> doInBackground(Void... params) {
    ArrayList<Movie> listMovies = MovieUtils.loadBoxOfficeMovies(requestQueue);
    return listMovies;
}

@Override
protected void onPostExecute(ArrayList<Movie> listMovies) {
    if (myComponent != null) {
        myComponent.onBoxOfficeMoviesLoaded(listMovies);
    }

}

MyService类

/**
 * Created by Macharia on 1/12/2016.
 */
public class MyService extends JobService implements BoxOfficeLoadedListener{
    private JobParameters jobParameters;

    @Override
    public boolean onStartJob(JobParameters jobParameters) {
        L.t(this, "onStartJob");
        this.jobParameters = jobParameters;
        new TaskLoadMoviesBoxOffice(this).execute();
        return true;
    }

    @Override
    public boolean onStopJob(JobParameters jobParameters) {
        L.t(this, "onStopJob");
        return false;
    }


    @Override
    public void onBoxOfficeMoviesLoaded(ArrayList<Movie> listMovies) {
        L.t(this, "onBoxOfficeMoviesLoaded");
        jobFinished(jobParameters, false);
    }}

0 个答案:

没有答案