推荐方式/为了从Web服务中读取数据,分析数据,并在一个SQLite数据库插入 [英] Recommended way / order to read data from a webservice, parse that data and insert it in a SQLite db

查看:174
本文介绍了推荐方式/为了从Web服务中读取数据,分析数据,并在一个SQLite数据库插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个开始提的是,我是全新到Android,我刚刚读完一个快速的,入门书,现在我要实现我的第一个应用程序。 这个程序将被用于接受订单。在所有的数据我将存储在本地数据库,两个表是最重要的:客户和物品,是后者最大的所有表(近似20000记录) 一个在我的应用程序的主要过程,获取所有我的应用程序需要脱机工作中的数据,当用户preSS启动的日常操作设备上的按钮。

嗯,这个过程包括以下步骤:

一个。阅读RESTful服务来获取客户的数据
 湾解析响应JSON对象
 C。这些客户将到客户表
 ð。阅读RESTful服务来检索文章数据
 即解析响应JSON对象
 F。将这些文章在文章表

这就是我打算做的:

  1. 在编写处理所有的HTTP GET请求一个辅助类。然后调用这个类,每当我需要下载所有的客户和文章数据
  2. 由于这一切的过程可能需要大量的时间,我需要做的是在后台。因此,基于一些建议,我打算把所有的code内的绑定服务。
  3. 当所有这漫长的处理发生在后台我必须表现出某种指标(一ProgressDialog)这是我选择使用绑定服务的原因

虽然我觉得我得怎么做大部分的事情的总体思路单独,我认为把所有的一起是一个完全不同的故事。

因此,这些都是我必须得说我必须把拼图在一起的问题:

  1. 你觉得在我执行所有的6个步骤中描述的过程的顺序是正确的/有效的?如果你不得不做出一些改变,你会改变什么?
  2. 如果启动该服务被明确取消或隐藏另一个活动的活动中,服务必须有办法让用户知道这个过程已经完成。我怎么能实现呢?
  3. 是否有可能/推荐的服务中写到的SQLite数据库?它是一样的,当我做这样一个活动中?
  4. 在J2ME我已经做了类似的事情,当我把类似的6个步骤我上面提到的所有的人都按顺序执行,也就是说,一个接一个。它是在Android上的一样吗?

我希望我没有问太多问题。我只是把它们放在一起,因为它们都是相关的。

基本上在这个问题上,我不要求工作code(尽管这将会是确定的,如果你能提供一些示例code)我真的很之后是一些建议,一些指导。类似的嘿,我想这可能会帮助你点数3你可能会发现这篇文章有用我想你最好关闭使用这个,而不是那个的。类似的事情。

我决定来找你,因为你是专家,我真的很需要有人把我在正确的方向。

非常感谢你。

P.S。请不要关闭这个问题,如果你觉得我需要改变某些事情只是让我知道,我会做到这一点。

解决方案
  

我决定来找你,因为你是专家

第一个我不是高手我不是知识渊博,你可以找到更专业的人比我这是我的意见 希望能给大家一些帮助

首先忘了使用的AsyncTask 来下载,因为它必须用于短期后台作业不喜欢你的,我认为你要下载文件的数量是pretty的大。(我想是这样)

检查下载管理器谷歌,看看它是如何工作的,它可以帮助你。

http://developer.android.com/reference/android/app/ DownloadManager.html

http://blog.vogella.com/2011/06 / 14 / Android的下载管理器,例如/

如果你想使用服务使用绑定服务,因为你不希望该服务由机器人被摧毁或用户,当用户关闭该应用程序是吗?我想你希望得到您的数据的方式。

为了我推荐这些措施是有效的:

一个。阅读RESTful服务来获取客户的数据

乙。当你的客户的数据做的:

  • 创建其他服务或线程来读取RESTful服务来检索文章数据

  • 解析在旧的服务或线程响应JSON对象

现在你有2个服务或同时运行,以便按照步骤明显插入 解析等主题,上的每个服务或螺纹

我为什么不结合A和D?因为我认为用户不喜欢等待后面的下载进度条的时间。

,以便插入您的数据的数据库使用交易,我建议你使用:

http://greendao-orm.com/

这是更有效的 ORM 比其他数据库,你可以免费从数据库的实现。

  

如果启动该服务活动被明确取消或隐藏的另一项活动,该服务必须有办法让用户知道这个过程已经完成。我怎么能实现呢?

使用的通知:

http://developer.android.com/training/notify-用户/集结notification.html

http://www.tutorialspoint.com/android/android_notifications.htm

http://www.vogella.com/tutorials/AndroidNotifications/article.html

  

虽然所有这漫长的处理发生在后台,我会必须表明指标(一ProgressDialog)某种这是我选择使用绑定Service`的原因

     

我如何从一个非绑定服务更新UI?`

使用一个 LocalBroadCastManager ,或在一般 BroadCastReciever

从服务 Android的更新活动的用户界面

  

在J2ME我已经做了类似的事情,当我把类似的6个步骤我上面提到的所有的人都按顺序执行,也就是说,一个接一个。它是在Android上的一样吗?

这是取决于你的脚步,如果你按照我的想法运行同时,如果你运行你的想法,你将运行依次

好运。

I'm one to start mentioning that I'm totally new to Android, I've just finished reading a quick, introductory book and now I have to implement my very first app. This app is going to be use to take orders. Among all the data I'm going to store in a local db, two tables are the most important: Customers and Articles, being the latter the largest of all the tables (aprox 20000 records) One of the main process in my app, fetches all the data that my app need to work off-line when the user press a button that starts the daily operations on the device.

Well, the process consists of the following steps :

a. Read a restful service to retrieve the Customers Data
b. Parse the response to Json Objects
c. Insert those customers to the Customers Table
d. Read a restful service to retrieve the Articles Data
e. Parse the response to Json Objects
f. Insert those articles to the Articles Table

This is what I've planned to do:

  1. Write a helper class that handles all the HTTP GET requests. Then call this class whenever I need to download all the Customers and Articles data
  2. Since all this process might take a lot of time, I need to do it the background. So based on some suggestions I'm going to put all this code inside a Bound Service.
  3. While all this long processing is taking place in the background I'll have to show some sort of indicator (a ProgressDialog) This is the reason I opted for using a Bound Service

Though I think I've got the general idea of how to do most of these thing separately, I think that putting the all together is quite a different story.

So these are the questions I've got now that I have to put the puzzle together:

  1. Do you think the order in which I'm executing all the 6 steps of the process described is correct / efficient? If you had to make some changes, what would you change?
  2. If the activity that started the service is explicitly cancelled or is hidden by another activity, the service has to have a way to let the user know that the process has finished. How could I implement that?
  3. Is it possible/ recommended to write to the SQLite DB within the service? Is it the same as when I do so within an activity?
  4. In J2ME I've done something similar, and when I put something like the 6 steps I mentioned above all of them are executed sequentially, that is , one after the other. Is it the same in Android?

I hope I'm not asking too many questions. I just put them together because they are all related.

Basically in this question I'm not asking for working code ( though it'd be OK if you could provide some sample code) What I'm really after is some suggestions, some guidance. Something like "Hey, I think this might help you with point number 3" or "You might find this article useful", "I think you'd better off using this instead of that". That kind of thing.

I decided to come to you because you're the experts and I really need someone to put me in the right direction.

Thank you very much.

P.S. Please do not close this question, if your think I need to change something just let me know and I'll do it.

解决方案

I decided to come to you because you're the experts

first i am not expert and also i am not knowledgeable you can find more expert people than me but this is my opinion hope to give you some help.

first of all forget to use AsyncTask to download because it must be used for short background jobs not like yours i think the amount of file you want to download is pretty large.(i think so)

check downloadmanager of google to see how it works it may help you.

http://developer.android.com/reference/android/app/DownloadManager.html

http://blog.vogella.com/2011/06/14/android-downloadmanager-example/

if you want to use service use unbound service because you do not want the service to be destroyed by android or user when the user close the apps do you? i think you want to get your data any way.

in order to be efficient i recommend these steps:

a. Read a restful service to retrieve the Customers Data

b. when you get Customer data do :

  • create another service or thread to Read a restful service to retrieve the Articles Data

  • Parse the response to Json Objects on your old service or thread

now you have 2 services or threads that run concurrently so follow the steps that obvious insert parse and so, on each service or thread.

why do not i combine a and d? because i think user do not like to wait much time behind download progress bar.

in order to insert your data to database use transaction and i recommend you use:

http://greendao-orm.com/

it is more efficient ORM than others for database and you get free from db implementation.

If the activity that started the service is explicitly cancelled or is hidden by another activity, the service has to have a way to let the user know that the process has finished. How could I implement that?

use notification:

http://developer.android.com/training/notify-user/build-notification.html

http://www.tutorialspoint.com/android/android_notifications.htm

http://www.vogella.com/tutorials/AndroidNotifications/article.html

While all this long processing is taking place in the background I'll have to show some sort of indicator (a ProgressDialog) This is the reason I opted for using a Bound Service`

how can I update the UI from an Unbound Service?`

Use a LocalBroadCastManager, or in general BroadCastReciever

Android update activity UI from service

In J2ME I've done something similar, and when I put something like the 6 steps I mentioned above all of them are executed sequentially, that is , one after the other. Is it the same in Android?

this is depends on your steps, if you follow my idea you run concurrently and if you run your idea you will run sequentially.

Good Luck.

这篇关于推荐方式/为了从Web服务中读取数据,分析数据,并在一个SQLite数据库插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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