简体   繁体   中英

android ListView background processing

In my application for Android 2.2 + I will use ListView and communicate with the existing XmlRpc server. User will manually add items to the ListView and application will receive additional information about items from the xmlrpc server.

The application will do the following activities:

  1. test the connection to the xmlrpc server
  2. retrieve information from the server for manually added item to the ListView
  3. retrieve information from the server for all the items in a ListView
  4. send a list of items to the server

These activities I plan to implement as:

  1. in onCreate() I will use AsyncTask to call xmlrpc function and then I will show OK/ERROR in status bar of application

  2. after pressing the ADD button I will use AsyncTask to call xmlrpc function to obtain information about the item (name, price, image) and then I will update the item just added.

  3. after pressing the GET ALL button I will use AsyncTask to call xmlrpc function to get information about all the items in the list (name, price, image) and then I will update all the items.

  4. after pressing the SEND button I will use IntentService to call xmlrpc function and after I will display the result in the dialog box.

Is it appropriate to use AsyncTask and IntentService for my needs? Thank you.

All internet communication shall happen in separate background thread, U NOT HOG UI THREAD, or your application will be killed by android OS. List views are not updated directly, but via their adapter which provides data and views for it. Assuming you have created and configured appropriate adapter, workflow will be as follows: - rpc calls are processed in some background thread - they update datastore in your adapter - they signal via notifyDatasetChanged() ( from UI thread ) - list view asks adapter to provide views for all visible list items - your interface is updated.

You do not neet to mess with intents when you stay inside same java process - standart multithreading will do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM