关于GcmTaskService几个问题 [英] Some questions about GcmTaskService

查看:532
本文介绍了关于GcmTaskService几个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我想用新的jobscheduler API,它是psented对棒棒堂$ P $,但遗憾的是它并没有为pre-棒棒糖。

正式口

然而,存在的GcmTaskService,它提供了非常相似的功能。

问题

这个API是相当新的,所以很少有地方寻找如何使用它( <信息STRONG>此处 和<一href="https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmTaskService">here,例如)。

的问题

我对这个新的API几个问题:

  1. 看来,它要求谷歌播放服务(<一href="https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager.html#schedule(com.google.android.gms.gcm.Task)">here)使用(除非使用棒棒糖版本的Andr​​oid,这将使用普通的jobscheduler时的),我应该怎么做的情况下,谷歌播放服务不可用?

  2. 看来,即使我用setPersisted(真)的重复任务,当我重新启动设备的任务将不会被再次调用。怎么来的? 编辑:那是因为我错过了RECEIVE_BOOT_COMPLETED的许可

  3. 什么是任务的默认行为,如果我不使用setRequiredNetwork?它是NETWORK_STATE_ANY?

  4. 的<一个href="https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmTaskService">docs说一下什么是从onRunTask回来后,我可以返回任何值RESULT_FAILURE,RESULT_RESCHEDULE,RESULT_SUCCESS的(信息<一个href="https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager.html#RESULT_FAILURE">here).看来无论是失败和成功的选项会做同样的事情 - ???从队列中删除该任务,是真的如果是这样,究竟是它们之间的区别难道他们不同的功能

  5. 是<一href="https://developers.google.com/android/reference/com/google/android/gms/gcm/TaskParams">TaskParams"只为任务的标签用?我可以以某种方式传递一个捆绑使用API​​的任务吗?不然,我需要设置一个数据库,用于存储什么应该被传递给任务,对吧?

  6. 是否有可能在该应用获取任务的队列?我知道这是可能使用亚行,但有可能使用API​​吗?

  7. 他们说(<一href="https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmTaskService">here) ???每个任务有长达3分钟wakelock应该做些什么,如果任务需要更重要的是是否应该收购另一wakelock为本身的API警告说,wakelock被释放下面是该文档说:

  

调度会召开PowerManager.WakeLock为您服务,   然而3分钟执行后,如果你的任务还没有恢复   中,将考虑到已超时,并且wakelock将   释放。重新安排你的任务在这一点上不会有任何影响。如果   你怀疑你的任务将运行时间超过这个你应该开始您   自己的服务或明或使用一些其他的机制;这个API是   针对相对快速的网络操作。

<醇开始=8>
  • 他们说(<一href="https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmTaskService#onInitializeTasks()">here)所有的网络任务的应用程序被升级/更换,每次取出,并有一个喊出了onInitializeTasks当这种情况发生,那你可以再次重新安排它们。我怎样才能重新安排这些任务?我不'T认为我甚至可以得到任务列表...

  • 是否有可能在白天告诉任务preFER具体时间?例如,之间的14:00-15:00

  • 我已经注意到,如果你计划任务,然后强行停止和/或应用程序的明确数据,该任务将仍然运行。我怎样才能避免这种情况?

  • 解决方案

    你可以找到答案,大部分的问题就在这里。

    https://github.com/jacktech24/gcmnetworkmanager-android-example/blob/master/README.md

    要未回答没有答案

    7:你不会得到通知时,wakelock被删除,因为它们在文档中说,这个API仅仅是短期的任务,如果你有时间越长,写自己的实施

    9:不,你不能截至目前,该API不允许它

    10:这是因为谷歌Play业务是照顾它,也没有办法解决它。你必须检测服务的应用程序是否设置(我希望这是你的问题),例如。配置创建等,并最终取消所有任务时,他们中的一个被称为

    Background

    I wanted to use the new JobScheduler API that was presented on Lollipop, but sadly it doesn't have an official port for pre-Lollipop.

    However, there is the GcmTaskService, which provides very similar functionalities.

    The problem

    This API is quite new, so there are very few places to look for information of how to use it (here and here, for example).

    The questions

    I have a few questions about this new API :

    1. It seems that it requires Google Play Services (here) to be used (except for when using Lollipop version of Android, which will use the normal JobScheduler). What should I do in case the Google play services aren't available?

    2. It seems that even though I've used "setPersisted(true)" for a repeated task, when I restart the device the task won't be called again. How come? EDIT: that's because I missed a permission of RECEIVE_BOOT_COMPLETED .

    3. What is the default behavior of a task, in case I don't use "setRequiredNetwork" ? Is it "NETWORK_STATE_ANY" ?

    4. The docs say about what's returned from onRunTask , I can return any of the values "RESULT_FAILURE", "RESULT_RESCHEDULE", "RESULT_SUCCESS" (info here). It seems both the FAILURE and SUCCESS options will do the same thing - remove the task from the queue. Is it true? If so, what exactly is the difference between them ? Do they function differently?

    5. Are "TaskParams" used only for the tag of the task? Can I somehow pass a bundle to the task using the API? Otherwise, I would need to set a DB for storing what should be passed to the tasks, right?

    6. Is it possible for the app to get the queue of the tasks? I know it's possible using adb, but is it possible using the API too?

    7. They say (here) that each task has a wakelock of up to 3 minutes. What should be done if the task needs more than that? Should it acquire another wakelock for itself? Will the API warn that the wakelock was released? Here's what the docs say:

    The scheduler will hold a PowerManager.WakeLock for your service, however after three minutes of execution if your task has not returned it will be considered to have timed out, and the wakelock will be released. Rescheduling your task at this point will have no effect. If you suspect your task will run longer than this you should start your own service explicitly or use some other mechanism; this API is intended for relatively quick network operations.

    1. They say (here) that all networks-tasks are removed each time the app gets upgraded/replaced, and there is a call for "onInitializeTasks" when this happens, and that you can re-schedule them again. How can I re-schedule the tasks? I don't think I can even get the list of tasks...

    2. Is it possible to tell the task to prefer specific times during the day ? For example, between the 14:00-15:00 ?

    3. I've noticed that if you schedule a task, and then you force-stop and/or clear data of the app, the task will still run. How can I avoid this behavior?

    解决方案

    you can find answers to most of your questions it here.

    https://github.com/jacktech24/gcmnetworkmanager-android-example/blob/master/README.md

    To answers that are not answered there

    7: You won't get notified when wakelock is removed, and as they say in documentation, this API is only for short tasks, if you have longer, write your own implementation

    9: No you can't as of now, the API doesn't allow it

    10: That's because Google Play services are taking care of it, and there is no way around it. You have to detect in the service whether the app is setup (I expect that's your problem) eg. configuration is created etc. and eventually cancel all tasks when one of them is called.

    这篇关于关于GcmTaskService几个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆