简体   繁体   English

如何将数据更新为活动?

[英]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 ). 有很多在网上的例子,这是非常直观的( 123 )。 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. 内容提供者是将一个进程中的数据与另一个进程中运行的代码连接的标准接口。

  • It uses a CursorLoader to query in background the data you need in your Activity/Fragment and when certain things happen, you can notify your observer to load more data. 它使用CursorLoader在后台查询“活动/片段”中所需的数据,并且在发生某些情况时,您可以通知观察者加载更多数据。 ( This good tutorial explains how to work with CursorLoader written by Wolfram Rittmeyer ). 本教程很好地介绍了Wolfram Rittmeyer编写的CursorLoader的使用方法 )。

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 . 有很多非常好的开放源代码应用程序来介绍如何解决此类问题,例如SeriesGuideAndroid的WordPressioSched 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.

相关问题 如何“更新”我的活动? - How can I “update” my activity? Android - 当收到推送通知 FCM 时,如何更新我的活动中的数据或 UI? - Android - How can I update data or UI in my Activity when Push Notification FCM is received? 如何将数据传递给我的应用程序中的活动? - How can I pass data to the activity in my app? 如何在我的活动中获取 viewpager 数据 android java - How can I get viewpager data in my activity android java 在我的活动(SQLite)中修改数据后如何更新我的片段? - How do I update my Fragment after data modification in my activity (SQLite)? Android Studio Java:如果产品已经存在于我的购物车活动中,我该如何更新我的数量? - Android Studio Java: How can I update my quantity if the product already exist's in my Cart Activity? 当我的方法不在活动中时,如何将其传递给活动? - How can I pass my method an activity when it is not in an activity? 当我在其他应用程序上时,如何在活动中更新我的位置 - How to update my location on activity when I am on other application 单击通知中的按钮时如何更新活动 UI? - How to update activity UI when i click a button in my notification? 如何在我的活动中查看寻呼机数据 android java - How can I get view pager data in my activity android java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM