douba9776 2017-09-30 17:17
浏览 25
已采纳

Android数据上传[关闭]

I am new to mobile development and still have much to learn. I have written an Android application that collects user data in SQLite database locally. I would like this data to be uploaded separately to users actions, which means:

  • When the user is using the application, all of the data is stored locally,
  • If the user has internet connection, data can be uploaded immediately to data server (no problem about the server side, php scripts are already written for data insertion),
  • If the user has no internet connection, the application will wait for any connection and then upload the data.

I would like to know, what is the best approach to do this - is it any kind of service running in the background, or anything else? I have read about services only in tutorials, so I don't know exactly how to deal with them and if I should even bother writing them, to achieve what I have mentioned above?

Regards.

  • 写回答

1条回答 默认 最新

  • douduan9391 2017-09-30 17:52
    关注

    Actually services are not so necessary for that (Example: if you have only one activity). Service helps you keep off thread work apart of activity lifecycle. Ok. Now, decision of your problem step-by-step:

    1. You need to create off thread work (AsyncTask, Thread etc.), which tries to send you data to server
    2. If it fails you can use "connection changed" listener of just schedule your next try with Handler.postDelayed
    3. Service only helps you to keep control of that off thread work from different activities if you need that
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?