I have read a lot of SO answers asking a similar question, but I believe my question is different. I have to load around 70-80K records from the cloud and display it to the user in a ListView. A few things that I want to be done :
I don't want to use a load more Button or load more objects when the user scrolls as I have a index from A-Z so the user could start my application and click on Z and the data should be present/available to him.
I have considered pre fetching the data using a splash screen but I was wondering if there is really any other optimised method to fetch such huge data.
I don't want to hang up the UI thread with the Loading progress bar.
I agree that this may be too much to ask for but I am just trying to see if someone has a very efficient way of doing this. I am open to ideas involving modifications in the backend on web service as well, so if you have an efficient way of achieving this using some modifications on the web service, that is also fine for me.
If it helps, look at your default contacts app, it has all the data ready and available to you when you open it. You can directly use the index to navigate to Z section. Just assume the same with 70k entries in the app.
Thanks in advance!
Here is the best solutions I figured out with the help of Tamal Mukherjee and Roman Nurik.
Tamal's solution :
Just load 5-10 rows/letter. Add a 'more' button or handle scroll event and load dynamically. Use SQLite to store data. Use background threads to fill up the db.
Roman Nurik's soltuion :
With 80k rows, that's well over 1000 items per letter in the alphabet. Seems like you'll need a lot more than letter indexing to make this UI usable. Why not offer filter-as-you-type? That'll result in more HTTP requests but might result in a better UX.
So i guess my implementation will be a combination of the both.
Please follow this step:-
1- Call API on splashscreen using IntentService.
2- Use static broadCasting and save API response into sqlitedb using ORMLite in onRecieve() method of BroadCastReciever.
3- Make sure there should be separate class for receiver.
4- Use Loader Manager for updating ListView.
Related
I am developing an SMS app. I am getting messages from the Android Database every time user opens the App.
On a device with around 100 messages, it works fine. But with a device with 10,000 messages the app takes around 20 seconds to display the list after getting all the information.
To solve this, I am thinking about three possible options here:
Should I consider saving all the data to my own database? Will it make it faster?
Should I get some messages first, and then the rest in the background?
Any other option you might suggest.
Thanks in advance.
Below are the answers of your question
1. Should I consider saving all the data to my own database? Will it
make it faster?
No, don't do that. This will not make it faster. Same response you will get.
2. Should I get some messages first, and then the rest in the
background?
You can do this, but there is no need to do this to get all messages in background.Because User can see limited number of messages and chances are he will not see all messages down the bottom. So it will be useless to get those in background (untill or unless there is a business requirement)
Any other option you might suggest.
Yes, you need to implement pagination and need to keep track how many messages are needed to be loaded first time and while user scrolls then get more messages. In this case you need to keep track your own about how many messages you have already loaded and how many more you want to load. TO achive this, you will be required to implement PULL TO REFERESH mechanism of android. And a lot of tutorials can be found over the web.
Hope that answers your question.
If I do need it, I'll have to modify about 15 classes (models and model-manager classes), so I really want to know if I need a ContentProvider.
Here's where I am:
Similar to Twitter, I'm getting rows of data from a server, and saving it locally in case the user has no Internet connection. But the ideal way is to always get it from the Server.
I am probably not going to use SimpleCursorAdapter because the rows of data I get from the server includes URLs, which means I have to create a custom adapter to display images.
I need to load data into the ListViews asynchronously because I'm having a ViewPager with 3 Fragments that shows the same data (different filters tho), so, since a ViewPager loads 3 Fragments into memory, it means 3 queries are executing (and that's most likely the cause of non-smooth swiping).
So far, the way I synchronize data between the App and the Server is:
Fragment.onStart() executes an AsyncTask which returns rows of data formatted as JSON data
Said AsycTask.onPostExecute() updates the List<E> and calls Adapter.notifyDataSetChanged()
The issue here is that each time I change tabs, the onStart() is called, ergo the AsyncTask executes causing the UI not being smooth.
Should I change the way I synchronize data with the Server, or should I use ContentProvider?
EDIT: as a head up, the reason I'm asking is that startManagingCursor() method is depracated. It says to use the Loader framework, but it seems it's only available through ContentProvider
You don't need to develop your own provider if you don't intend to
share your data with other applications. However, you do need your own
provider to provide custom search suggestions in your own application.
You also need your own provider if you want to copy and paste complex
data or files from your application to other applications.
from http://developer.android.com/guide/topics/providers/content-providers.html
I wrote a custom CursorLoader based on the SimpleCursorLoader source code that comes within the support library. You can search this site for more information about writing a custom one.
I am having one web service in which i have list of countries, state and corresponding cities of it. Now I am little bit confused in pulling this data in my Android app. Right now I have only 2(USA,Canada) Country data with me but it might be increased in future. Also I have list of state in this country and yes the cities in every state.
I have one splash screen in my app in which I have written the logic of getting country and on the basis of that i am getting state and then cities for every state. But its long process and if i publish this a user will be frustrated by waiting time. So I don't want to use this way which takes longer time for pulling data. Is there any other way or suggestion for me to achieve this.
All suggestions are welcome.
you should use AsyncTask to perform any web data downloading (and uploading), it works in the background and does not block UI thread, so your user won't notice.
also, it might be a good idea to supply default country/city data along with your application and then download only changes/updates.
Use a Service or intent-service, to download the data in background. and when the download is complete you can display the downloaded data using onbind. service runs on a seperate thread.
You could simple use the system DownloadManager to get the files from your sources and later process them. The DownloadManager will even inform you when the file is fully downloaded.
Take a look a https://github.com/commonsguy/cw-android/blob/master/Internet/Download/src/com/commonsware/android/download/DownloadDemo.java for a simple example code using DownloadManager.
Is there a way to cause my app to update itself at exactly midnight every night? I need the new content to be displayed on the app right when it hits midnight. I have an idea of how to accomplish this, but if it isn't in another thread and is in the onCreate and the app is running in the background next time it is opened it would just display the previous info and not the updated?
I could also use help accomplishing this same thing with iPhone as well.
I will clarify a bit. So all the information that is to be displayed on the app will be in the app already. I simply want the content (whats displayed) on the app to randomize and then display the new group of content only once per 24hours or at exactly midnight. Hope that makes it more clear.
Android:
You can set pre-determined times to update with AlarmManager
You can look at a snippet here: Android: How to use AlarmManager
iPhone:
With iPhone you probably have to download the content whenever you re-open the app.
Can't you just have the app update the content upon launch, or when entering the foreground in the appDelegate.
This question is very vague - but if I understand the requirements correctly you will need to serve the application's content dynamically via a content server (or some type of a CDN). In this case there could be various scenarios.
In the easiest possible implementation, you could have the application be powered by data (XML, JSON, etc...) from something like Amazon S3 and have logic within the application to know how to fetch the correct data depending on the current day.
This wouldn't be extremely difficult to implement, but it would require building some type of cross-platform framework that reads the same kind of data for each application.
Is the content available before midnight?
If so, can't you have the app download it in the background beforehand and then make it available exactly at midnight?
If not, there's surely going to be some delay anyway.
app can not update itself at least in iOS apps.
I'm getting hung up on how to handle the data for an app I'm designing. I want to pull a list of items from the net. The data is updated routinely, and I think it would be good to store all the data on the device so the app can load quickly and refresh the data in a background thread rather than have to wait for the network on every start-up.
I think I should make the data available in an XML and have a thread parse and save into a SQLite DB, but I'm not sure if that's the "best practice." Are there other ways that people go about handling this?
The cleanest way (or at least, I think it is the cleanest way) is to implement a custom ContentProvider class that interfaces with your server. You can query the contenprovider and if it doesn't have the data in a local cache (for example a SQLite db as you said) it downloads it from your server and adds it to the local data. Why a content provider? because then you can easily access your data across apps and you have a nice and clean way to get your data when using intents.
Also, I personally prefer not to download data when the app is not running, because it will cost battery life while the user does not actively requests the data.
Sounds reasonable.
If the download of the new data takes more than some seconds, you might want to use a Service. This will allow you to continue the update even when the user has left your app.
Also, think about how you will notify the user that something is going on. Displaying some progress indicator is always a good idea. Otherwise, users might just think the data is not up to date because the app is broken.