How to reload fresh data from web in background - android

in my Android app I have a ContactList downloaded from web. I need it in many parts of the app, so i download it at login. This call is paginated, so i need to call the method many times (depends of the contacts number), and I've seen that REST call in 3g connection are sequential.
Users from their app can edit their name, surname, email. So I have to reload the contact list not only to add new ones, but to update users information too.
The solution for this waste of time at login is to save my user array list into a file, at login open the file and use the old list and then, in background, dinamically download new fresh data and change every single user data with the new fresh one. Is this possible? how to do that?

you can use GCM for that which pushes updates to phone as soon as they happen on server. you can load the contacts at login, but as soon as something changes or created on server you can inform the user about it and can only load that Contact.
check link how to implement it
http://developer.android.com/google/gcm/index.html

Related

Update cached data with real time updates

I'm currently working on an android app and I'm using firestore as my storage method. There is a feature in my app that, after a user selects a city, It downloads all it's stores. Given that those stores do not change often, I'm using a flag to know if the stores from one city had been downloaded before, so that I can use cached data instead of server data. My problem is that, if the info of a store changes, a store is added or a store is deleted, the only way the user can get the updated data is to "force download" the city again.
I would like to add a real time listener for a city instead of force downloading. The thing here is that I don't know that, for example, if I have all the stores in cache and suddenly the store "ABCD" changes and triggers my snapshot listener, will it update my cache data as well? If not, is there a way to achieve this?
Thanks!
If you don't have a listener active for the documents of interest that might change, then nothing will change in your local cache. You simply must have that listener active in order to get changes to documents as they happen, and that will cost document reads.
Consider using Firebase Cloud Messaging from your backend to tell your app when data has changed, and it can query that data as needed. That will be a fair amount of work to set up.

Populate data in the application with out sign up android

I am developing a news application. I dont want users to register in the application. When users download the application, data should be populated in the app from the server and any data added should be updated in the application.
How to update the data when any news has been added i.e how to identify users and send the data?
Your server don't need to track the new user. It is your app which will tell the server about the user. Write your data fetching code on the very first screen of your application (say Splash screen) and do check if there is any update on the server end
You can use the concept of fetching data on your Splash Screen, but if you dont want your user to get stuck you can use Intent Services to fetch your data in background, Once your data is received from server you can show it to the user.
How to use IntentService

How facebook shows the data to user in Android application?

I am working on an application which shows so many data to user, but problem is that it takes too much time to load data even we are using paging too. I want to know how facebook shows the data to user. are they storing the data in database first and then display it to user? if yes then how they maintain the user activity on that.

How to maintain data or show stored data in app until recieve response from server?

I need functionality like facebook app in my app.
the functionality is that when i login in facebook app then feed data load first time and if i click another tab ,like notification tab then load notification list in facebook.
but if i click again feed tab then all feed data showing instantly ,it's maintain cache or database and it's perform like and share functionality.
in my app when i click home tab then loader visible to fetch data from server and click to another tab then fetch data from server.
the question is that i dont want to load every time loader in my app,it's should be first time in every tab, if data addded in my appp from server then i call webservice.
Thanks in Advance.
Forgive me if any type of grammatical mistake.
Well I am not going to help you with code. that's your part. What I can do is give you some idea how to do that.
--> When the application first launches.
What you can do is fetch the data the first time you load app and store it in your SQLlite DB. the relations should match the server side but you can store data how ever suites you best.
--> when you switch tabs.
Save the state of the previous tab this question might help.
--> when you switch to a tab
trigger a run in background or Async Task or a thread to retrieve data from serve and store it in the same local DB. and bind the views to that data for example if you are updating a list calling notifyDataSetChanged() will actually update that list on the screen.
Thats it. Hope that helps.

How to handle gaps in local cache

I have an application that aims to behave like the instagram app. This means:
When the user opens the app, latest content from the local database is displayed, but a request is fired to get the server's latest content. If the server returns such data, the local database gets populated with it and then the UI displays it.
So, how can I handle the gap that this can create between the records that already existed, and the newer ones? Let's say I get 10 items per page from my API, and there are 15 new ones. When the request returns, the latest 10 items get inserted in my local database this leaving a gap of 5 items with the ones that were already there. This could even happen several times if the user doesn't use the app a lot, and the gap could just be huge if they haven't used it in a while, so just firing a lot of request doesn't seem to be the solution.
And the second thing is stale data. Items that have been updated or deleted on the server. I can provide an endpoint to retrieve changes, and soft-delete records so they can still be get but with a "deleted" flag. But the question is: when and how should I request that? It doesn't simply belong in to the "Enter the app -> request latest items" flow. Should I just poll regularly, use some sort of notifications maybe? Then what if the user is offline?
I'm puzzled and I've been googling A LOT lately, and I haven't found a convincing solution. They all are SyncAdapter style stuff.
Thanks.
I'm not sure specific on instagram, but on the app I work on and what I see around other apps, is to delete the feed of local data when you GET the page 0. Then as the user scrolls down, it reloads from internet the next pages.
What I mean by "delete the feed of local data" is, for example:
request is page=0 of friends_recents_photos
onSuccess -> DELETE friends_recents_photos -> INSERT new data
then onScroll -> loadMore
request page=1
onSuccess -> APPEND new data AT end
but that's only the request data of that specific feed, other feeds (e.g. followers), detailed information (e.g. UserData) or cached/downloaded images is kept in cache for fast access.

Categories

Resources