My app requires real time updating of information, i.e updates around every 20 seconds, and the size of the data can vary (can be >4KB).
What would be the ideal method of polling the server for data or even somehow pushing the data to the client instead? I'm guessing one of these methods https://developer.android.com/topic/performance/scheduling.html would be suitable but not sure which one is suitable for my needs. Are there other more battery/data efficient ways of doing this.
The app only needs to receive information when it is open and in the foreground.
Thanks in advance
Related
Though as a beginner, I am trying to develop an android app which is story based, i will like to know the best way to serve content to the user, i mean like a continuous update of content, just like updating news by the hour. As users will install just once, how will they get the latest content of my news or story based app.
I have access to domain names and hosting if it requires uploading such content through a domain.
from your experience, what is the best method to achieve this? I humbly await a response, thanks
So given the clarification in the comments this is the answer:
The best way is PUSHING the content to the user's device.
Generally speaking, the two ways for a new content to reach an app are :
1.polling your server (or any third-party server) for new data every,say, 20 minutes. The disadvantage of this method is that it drains the battery. Every time that the phone connects to the internet, the radio in that phone stays on (or in a standby mode) for something like 2 minutes. Those modes (on and standby) drain the battery. Another problem is that it does use data needlessly and in some countries cellular data is expensive (Canada for example).
This could be a solution if the data changes very very frequently (for example a stock's price can change many many times a day). But generally speaking method 2 is the preferred method..
2.Pushing the content to the user's phone.
Your server will send a message to the device once new data that you want to send is there (and you could also put that data in the payload of the message if it's not too much).
This means that the phone will connect only when some new data is available.
Saves battery life,and gets the information as soon as it is available!
I recommend using GCM (Google Cloud Messaging) for this purpose which is free, and simple to use. If you have no idea how to do that in Android (which is likely since you said that you are a beginner), it is explained really well in Udacity's
Advanced Android App Development. It is a free course by Udacity and Google, but the section about GCM is only about 15 minutes long.
If you know how to implement a server but don't know how to use GCM in your server (and you don't find Google's documentation helpful) do let me know..
If you don't know how to implement a server...well then it's something you will have to learn in order to get your content to your users as that's the best way.
I hope this helps! :)
For one of the screens in my android application, I need to listen to server indeterminately - ie; I have few fields in the screen whose values change continuously so long the screen is kept open. The values to be updated will be provided by the server continuously. I understand that normal http connection would not be a solution here. Also, I do not wish to make continuous http requests owing to performance reasons. What is the best way out in order to accomplish this.Is GCM Cloud Connection Server a good solution for my requirement. Or are there better solutions? Please advise.
Any help is much appreciated.
I think there are a two options. If you don't own the server yourself I would start a service to run in the background and bind to it. The service would poll the server at some time interval depending upon how often you want the values to update. The activity would then receive periodic updates and update the views. Given that the information that you're updating is really not all that large, updates every 30s to a minute wouldn't take a toll on performance at all since all of the work would be done in an asynchronous task.
Using an AlarmManager to accomplish this.
If you own the server then you could implement the GCM model, and only send updates when data changes. This is assuming that every user of the app would get the same set of updates of course.
Introduction to GCM
Keeping screen on could be battery consuming. If you own the server the changes can be pushed to the app using the GCM service.
As far as I understand, GCM bundles push messages from several server trying to push the messages together and hence is an optimised way to communicate.
Alternatively, you can bring up a server which can keep polling the original server and push the changes to the app through GCM.
I am building an app that shows user's friends' real-time locations on a map.
Each user updates his currnet location on the server (Parse.com) every defined interval (time and distance).
When a user opens the FindFriends activity, he'll get a map with markers on friends locations.
The friends locations data can be retrieved in two methods:
When activity is running, I am calling an AsyncTask that will download locations data from the server in a while loop (inside doInBackground), and after each time I call publishProgress() to handle the changes on the map.
I wrote a cloud code that is called every time a user updates his location on the server, which sends push notification to the relevant users (the user cant see the notification). When the FindFriends activity is running, a broadcast reciever is getting those pushes and update locations data on the map.
My question is: Which method is better for my needs or maybe I should do it differently? Of course I would like to keep battery consumption to minimum but not at expense of getting almost real time data.
I don't really think that this is an appropriate question, since you really should just make a prototype using each implementation, and see which is more performant in your particular use case. However, I can say that I definitely prefer the cloud solution. I've used GCM to implement a messaging client, and from my testing the updates are definitely really quick (very little noticeable lag time, when testing two clients side by side). So, I don't think that implementing it with GCM would negatively impact your user experience, and it does have the plus side of eliminating pointless server polling when, potentially, no updates could be present - which saves on battery.
If you want real time data then push notification GCM is not a good idea because, there is no guarantee that all users will get push notification in time. Sometime you will encounter delays in push notification.
Under given circumstances AsyncTask or Service can be a good way to perform required task, if they are handled properly. You should have control on AsyncTask/Service so that you can stop it any time you want.
I am designing an Android application that needs to receive constantly changing information (so the update interval must be very small).
Right now I am reading this information by consuming a REST WebService, but I am wondering if this is the best approach, regarding the battery drainage. This application would have to refresh the data being shown very often (specifically GPS data read from another system).
I have been reading about Google Cloud Messaging but I didn't find any comparisons between the two approaches.. Theoretically both approaches fit my needs since the data changes so frequently that it doesn't really matter whether it is updated by request or on a timer..
So my question is: Should I stick with WebServices or shift to GCM? Is there another battery-efficient solution?
Thanks in advance!
GCM utilises a connection that is already there - using this over your current polling methods is definitely recommended and will be much friendlier with the battery.
Think about it, in your case GCM will send you a notification to let you know you need to refresh data so instead of just calling refresh you have: receive the notification, process it and then call refresh. So if you need to refresh so often, like just say each minute and it's constant just skip the notification.
I would set a recurring alarm, get the intent in a BroadcastReceiver and trigger an IntentService for the refresh
I just finished an app that synchronizes its data with a server (runs SyncAdapter on background). I installed it on my phone, let it run on background (I barely used my phone) and I found out that the 23% of my applications' battery usage belongs to my app, so I really need to decrease its battery usage.
Right now I have the sync time set to 30 seconds. It's a multi-user app and if other users interact with you you get a notification, I can't set a sync time too high (actually I wanted to decrease it until I saw the battery usage).
In each synchronization it ALWAYS asks the server for any changes and checks for changes in the local database. If there are changes in the local database they are sent to server, and if we retrieve changes from the server they are applied to the local database.
Does anybody know about some tips to reduce battery usage?
Probably the best that you can do is to implement GCM (Google Cloud Messaging) using pushing instead of polling.
In this way you will be able to get a "tickle" when something new happened and you will know when ask to the server for datas.
A network poll each 30 seconds is very aggressive. I recommend you read this article from Google : http://developer.android.com/training/efficient-downloads/index.html
However, if you really need to request the network that often, I don't see any magical trick for you...