简体   繁体   中英

Best way to start an application efficiently

It's in the question, I would like to know what is the most efficient way to start an Android application that need :

1- xml/json stream to be downloaded with WebServices (text, image url, dataq, ...)

2- Data saved in sqlite, and then loaded to be used in the application (data from 1-)

3- Data saved in SharedPreference loaded to be used in the application too (some user inputs)

4- Images to be downloaded from url (urls from 1-)

What I need is a good way to start an application with all the constraints (data loading from webservice, sqlite insert/update, ...etc) but for the application to be launched the fastest possible and the data to be loaded the must efficiently.

I'd say that on pure speed this is the order; SharedPref - SQLite - xml/json.

Making a network connection is always slower then doing something local on the machine itself. Even if it wouldn't be in perfect conditions, you can not assure perfect mobile internet and server performance. After that, you still have to parse it.

SharedPreferences aren't made for saving whole data structures, just for simple things as small settings which you want to hold on to for a while.

What you want to do with your data is load it from the server once. Preferably without showing loading screens etc. Save this into a the SQLite database. On the next start-up, you can (almost) instantly show the data from the database, and update from the webservice in the background to keep up to date.

Good question ! I'll answer with a list of awesome libs. First you should definively have a look at AndroidAnnotations This will really simplify your work. Don't be afraid of perfs on Annotations. it's not reflexion but a compilation step. It really eases the use of shared preferences. For http stuff , spring is pretty good and well integrated with android annotations. I never used xml in WS, But for json mapping , i use Jackson and it's pretty fast and flexible. I think gson does the job well too.

For image loading, UIL is the most efficient and the most mature ( so, it was the case in July when i benchmarked, Picasso and Volley too).

For now i have not found the ORM saint graal, but my advice is "Does you really need a database ?" if you got a doubt backoff. if you need it, ormlite has some perfs problems. In my next project ,I'll give a try to greenDao.

Definitively use a CursorAdapter for ListView+ SQLite , instead of loading in Listview. But be sure to not access the database intensively at the same time (WS writes).

If you need to pass events like "Hey new data is available in database refresh", don't make boilerplate interfaces. Use an event bus this is awesome EventBus

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