I working on my app that uses "The movie database API".
This app just parse a json from the API and gets each movie information.
My question is what the better way to that.
First alternative is to build syncAdapter, check for updates each day for example, store all movies information on local database and update the UI from database.
Second alternative is just retrive the information from network on each request and update the UI.
Can anyone explain me wich way is better and why?
Absolutely the first alternative !!!!!
let's Suppose your app is used by thousand of users and you have chosen the second one .....oh poor server :)
I usualy create my own local database and syncronize it each "x" interval time depending on the type of information : if I have, for example, a list o category that I know they are rearly changed than I syncronize them each "2 days" ....For data that can be different more often I use 20 minutes and so on. This just avoid stressing server if the user goes in/out from your app.
Bye
Related
I created an android app where I tap on the screen to put some waypoints , get their position and some extra data, then post the data using cakephp. I want to know what are the best practice to send data for my case ?
Example, should I post every point once I tap on the screen or store all the data and post it once for all or post every point into a temporary table then when I click submit I post the data to the real table ?
I really want to know if there are other solution to optimize my application and the loading time ! Thanks.
If the positions are not used by other users until the user completes their interaction I'd save all the positions and send them as a http POST in JSON format as an array [[0,100],[100,331]] or [{"x":0,"y":100},{"x":100,"y":331}] depending on if you're really wanting to optimize it or not use one or the other.
If the positions are used by other users on the site in real time, send every position as they are selected.
I'm developing in app, in which user can add weather card to know city weather. I'm able to populate cities with Google Places Autocomplete API & also can able to retrieve weather of selected city.
But my problem is as weather data is not fixed, it changes over time. So how can I update weather data in background once user creates that weather card. I need to do updates in background, I think I've to use android service but don't know where to start.
Ok, I will only guide you here,Nobody will provide you full code neither i will recommend anybody to do so, It is for your own good. You need to practice and explore the android programming world. So, here is my guidelines for you.
FirebaseJobDispatcher will fix you problem here. Before moving towards the FirebaseJobDispatcher you need to create a service class. For Services in android you should check this out.
Lets Talk about your service class.
Lets say it is FetchWeatherData class FetchWeatherData will extend to IntentService and will implement some methods. Inside onCreate you will write logic for fetching data from the server. Once you get the data from server you will store into the Database. Before storing into database you should check if database have the any record in it? If it does then delete it and store the new records in it.
Lets Talk about your Activity. Lets say it is ShowWeatherActivity. You will check first if you have any record in your database if there is no record then you will use FetchWeatherData to download weather data. Then show it.
Answer to your question can be very lengthy but i tried to explain as much which can help you get the idea of sync flow. Ofcourse your problem won't solve by reading this answer only. You need to go through these concepts
Services (Runs on main Thread)
Intent-Services (Runs in background)
Sqlite (For storing data)
I have added the helpful links in answer. Follow them. I hope this will help you somewhat.
I'm writing an android application that has a search feature that needs to autocomplete from a list of stores. This list will only have up to a few thousand stores in it.
My current methodology is to send a LIKE query to the database every few hundred ms after the user has stopped typing and to populate the autocomplete list with these results.
Would using this method be stressful to the database?
It has been suggested to me that this wouldn't work because making continuous calls would be poor for users with a slow connection and that I should load all the stores into memory and filter from there.
At my work I ran into a similar problem a few months back. The contents of a text box filled by the user were supposed to filter their available options to choose from in a list of strings. The list needed to be updated every time the user typed a key so database calls to fetch records that matched their text were being made several times a second.
This ended up being wayy to slow to update as someone was typing, and this was only with several thousand records and with a server that was being accessed on site.
If you want to update as quickly as someone can type, making that many database calls simply won't do. Users will get pretty antsy having to let their phone buffer to type in some text.
In Short: Make one databse call and load it up onto the phone, and run your filter algorithm from there.
Regularly syncing the list of stores from your back end to the user's device and implementing autocomplete locally is the best way to go.
The JobScheduler API provides a flexible way to set constraints on your background syncing processes.
I want to do "bus plan app". I have a question to you:
What way will be better to code plan?
in array, in data base, other way?
I don't want come to death end and go back to start point again.
I was thinking about array:
String bus_stop [one element - bus nr.] [arrive time] [departure time].
Where arrive time is mostly the same what departure time, and sometimes arrive time have 8 elements and other time have 38 (the same departure time). I think plan for next year is going to change, so important for me is to easy new plan update.
I was never before use database, but it's seem easy way to store and show data to user.
So please help.
I would defiantly use a database, using alternative approaches such as storing data in RAM or XML files can be quite RAM intensive and could slow down your app. as #SMR said, using a database would give you much greater flexibility and integration with other services (API's perhaps?)
As you stated you have never covered databases before I'll share a link to a tutorial on how to get started with SQLite on Android, Its the simplest way to integrate a database (and maintainable persistent storage) from within your android application. Link: http://www.tutorialspoint.com/android/android_sqlite_database.htm
The situation: I have many real life locations with specific information associated with them, and updated frequently. I am unsure of how to store this information for use in an android application.
My original thought was storing the data on some server/cloud source/database, reading from the server from each Activity in the app to make sure the info is up to date, and update the server with any changes that may or may not have been made.
For example: there are 200 people inside the library, one person leaves.
So we would read the number of people from the server, display this on the app, person leaves, subtract one, send the new number back to the server.
Would this be an incorrect approach? I'm fairly new to Android in general, and I really have no experience on how to approach this type of situation, what services to use, etc.
I would look into using Parse, its a pretty sweet way to power the backend, and their website is very detailed in explaining how to use it.