J'ai découvert la bibliothèque this qui semble être très puissante, mais je n'arrive pas à comprendre comment l'utiliser. Je dois faire un travail qui commence quand Internet est connecté, même si mon application n'est pas au premier plan. Mon travail envoie une requête à un serveur Web pour obtenir des données et je souhaite que mon travail stocke ces données localement dans un fichier XML. J'ai vérifié this tutoriel sur Android-Job bibliothèque, mais il planifie le travail dans la méthode onCreate
MainActivity
, donc mon application devrait être au premier plan.Comment exécuter un travail d'arrière-plan avec Android-Job
Alors, est-il possible d'exécuter un travail en arrière-plan lorsqu'une connexion Internet est disponible sur Android N ou est-il obligatoire d'avoir mon application au premier plan en raison de nouvelles restrictions de services d'arrière-plan?
EDIT
Ceci est mon logcat:
05-25 16:14:06.300 892-904/system_process I/ActivityManager: Force stopping clyky.cartracker appid=10117 user=-1: set debug app
05-25 16:14:06.392 13046-13046/clyky.cartracker W/ActivityThread: Application clyky.cartracker is waiting for the debugger on port 8100...
05-25 16:14:06.542 13046-13052/clyky.cartracker I/art: Debugger is active
05-25 16:14:06.592 13046-13046/clyky.cartracker I/System.out: Debugger has connected
05-25 16:14:06.592 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:06.792 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:06.993 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:07.193 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:07.393 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:07.593 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:07.793 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:07.994 13046-13046/clyky.cartracker I/System.out: waiting for debugger to settle...
05-25 16:14:08.194 13046-13046/clyky.cartracker I/System.out: debugger has settled (1483)
05-25 16:14:08.289 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:08.731 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:08.777 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:08.821 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:08.870 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:08.911 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:08.954 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]asses.dex) because non-0 exit status
05-25 16:14:08.999 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:09.041 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:09.087 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:09.136 13046-13046/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:16.632 13260-13260/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.031 13260-13260/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.103 13260-13260/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected]_lib_slice_1_a[email protected]) because non-0 exit status
05-25 16:14:17.148 13260-13260/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.221 13260-13260/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.282 13260-13260/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.338 13325-13331/? I/art: Debugger is no longer active
05-25 16:14:17.461 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.830 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.904 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:17.954 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:18.027 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:18.082 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:18.125 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:18.173 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:18.235 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:18.310 13325-13325/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
05-25 16:14:18.408 13325-13325/clyky.cartracker W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/clyky.cartracker-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/[email protected]@[email protected][email protected]) because non-0 exit status
J'ai essayé votre solution avec un nouveau service, mais mon travail est jamais prévu (le 'onRunJob' il n'a jamais atteint) – Clyky
@Clyky J'ai mis à jour MyJob – shmakova
J'ai essayé d'enlever '.setPeriodic (60_000L)' parce qu'il a provoqué le crash de mon application, mais maintenant il plante quand il atteint la méthode 'build' – Clyky