[英]How can I update my data into my activity?
I have a small problem to display data in my application. 我在应用程序中显示数据有一个小问题。 Actually for updating my data I wrote all the methods in the
onCreate()
method. 实际上,为了更新数据,我在
onCreate()
方法中编写了所有方法。 So the problem is one all the data getting only the display will start. 因此,问题在于所有仅获取显示的数据将启动。
But I need to show some data first after that I will update remaining data in the background.So please tell me where can I write the other methods. 但是我需要先显示一些数据,然后再在后台更新剩余数据,所以请告诉我在哪里可以编写其他方法。
code: 码:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.summary_main);
displyProfile(personalDetailsInfo);
displyConditions();
displayAllergies();
displayWellness();
displayVaccine(vaccineHashMap);
}
First of all, creating an Android app that synchronizes with a Web service is not a simple task. 首先,创建一个与Web服务同步的Android应用程序并非易事。 You must take care of a lot of different things to do it properly (and it really depends on the application you are building and the nature of it).
您必须照顾很多不同的事情才能正确地执行它(这实际上取决于您正在构建的应用程序及其性质)。 Sometimes you can use an AsyncTask to communicate with your webservice as @Roshni has said, but IMHO it's not the best option you have for this task (especially if you rotate your device ;D).
有时,您可以使用@Roshni所说的,使用AsyncTask与您的Web服务进行通信,但是恕我直言,这不是您执行此任务的最佳选择(尤其是如果您旋转设备; D时)。
If you want a behaviour of Google+ you must keep in mind that it's using a lot of different components: 如果您想使用Google+,请记住它使用了许多不同的组件:
It uses a Rest Library (like Volley ) to consume an API. 它使用Rest库(如Volley )来使用API。 There are a lot of examples in the web and it's very intuitive ( 1 , 2 , 3 ).
有很多在网上的例子,这是非常直观的( 1 , 2 , 3 )。 Probably if your application is not very complicated you can use only this component and it will suffice.
如果您的应用程序不是很复杂,则可以仅使用此组件,它就足够了。
It uses a SyncAdapter to synchronize its content with the API. 它使用SyncAdapter将其内容与API同步。 Developers docs says this about this component:
开发人员文档对此内容进行了说明:
The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server.
应用程序中的同步适配器组件封装了用于在设备和服务器之间传输数据的任务的代码。
Content providers manage access to a structured set of data.
内容提供商管理对结构化数据集的访问。 They encapsulate the data, and provide mechanisms for defining data security.
它们封装数据,并提供定义数据安全性的机制。 Content providers are the standard interface that connects data in one process with code running in another process.
内容提供者是将一个进程中的数据与另一个进程中运行的代码连接的标准接口。
There are a lot of very good Open Source applications to take a look on how are resolving this kind of issue like SeriesGuide , WordPress for Android , ioSched 2013 . 有很多非常好的开放源代码应用程序来介绍如何解决此类问题,例如SeriesGuide , Android的WordPress , ioSched 2013 。
Probably in your case if your data is simple you can use Volley and query the data you need, it will handle all asynchronous fetching for you and notify a corresponding listener, then in your Activity/Fragment you only have to update the related views. 在您的情况下,如果您的数据很简单,则可以使用Volley并查询所需的数据,它将为您处理所有异步提取并通知相应的侦听器,然后在Activity / Fragment中,您只需要更新相关视图即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.