My app periodically refresh data by pointing the api. Right know this process is every 3 minutes. Thats mean that every 3 minutes app, points to api requests and calculating data.
What is the best time value between refreshing points? Somewhere i ready that good is every 30 minutes.
I focusing right now on battery life and looking for the best solution.
Thanks.
Exact answer for this question depends entirely on how important is "refresh" for your app to work stably. I haven't checked the c2dm approach.
Few steps can be followed to improve performance and battery
1) Stop your periodic refresh when application is in background
2) Follow the design tips thats been given here.
3) Its better to give user a choice regarding Refresh timer with 10, 20 , 30 minutes as choice in your app settings (optional).
You can use Google's C2DM to notify the device of new information instead of polling for it. Yes 3 minutes is too soon, use 30.
Related
I am making a mobile application and I need to have the current time. However, I don't want to depend on the user's phone time since it can be changed to whatever they want. Is it a good practice to fetch from a server its local time every minute or similar interval?
P.S: The app will use the time to show if a shop is open or closed so I don't mind about different timezones, I only need the time in the server's timezone.
Depending on the need of the application. If your application would require a connection from the internet, then yes. You can also put that in case there is an issue catching the online time, you can just take the user's time.
From personal experience I never had issues that the user would want to change their phone time, but there have been a few exception.
To use server times is fine. But based on that making decisions on data (shop open/not) is not a good practice. Whenever you make an api call, get the status if its closed or not. This will avoid user side data issues
If you want to show this information on a single shop page, fetch the time difference between current time and closing time from the server. This will help you to maintain the status on app side. this should not be for a very long time. You can use this solution if the difference is less than 10 or 15 mins.
I want to practise my Android development skills by creating an app wich sets 2 locations. To make it more interesting, I only want to set them while I am driving / arrived. The first, startLocation is created when the user is faster than 19km/h. I get that at the onLocationChanged Event with FusedLocationApi from google.
But obviously, there is the question when to create the endLocation. My solution for that would be to run a handler if the speed is less then 19km/h and wait 2 minutes. If the speed doesnt get faster then 19km/h within 2 minutes the endLocation get set.
Having said that I would like to hear some other solutions for that problem.
Thank you
That's the solution I used when I wrote a similar app 5 years ago. Since then Google came out with activity detection, which determines if a user is walking, biking, or driving. I'd just use that now.
Solution with handler that waits for 2 minutes is not the best, because
by that time your activity might be destroyed.
You can schedule task using Alarm Manager
Or if you are using API 21+ the best option is enter link description here
Using google maps api to create a route while the app is open.
right now, I am updating every second. is this fine? how often does the google maps app update for example? Does it kill the battery/hog the CPU if I have the location updated every 1 second?
thank you
Once a second is fine.
You cannot save battery by updating once in 5 seconds.
To save battery you have to request in a much lower frequence, like once in 20 minutes.
It depends of your application how accurate the tracking must be and how often you need a location.
I think it depends on how precise your app should be. It is true, that having a short delay drains battery, but if you want to track user's movement precisely, you have no choice. Try to approximately check GPS interval of some similar tracking apps, but I think that many of them just keep GPS turned on.
Play with it and you will find the ideal configuration for your desired app. :-)
I want to develop this simple instant messenger application. Now i can send text to database. Now i want to show a notification to the user if he receives a new message.For that i think i want to check the remote database after fix time i.e every 20 sec. What is the best way of doing that??
I know my question could end up being lame and this might not be the best technique to show user notification of new message but for now i just know that so i am implementing it . .
Suggestions are always welcome . .
Use a timer in a service, so it can occur even if the app is not in the foreground. As an aside, I wouldn't do it every 20s- far too often, if you got a significant user base it would cost you a lot of bandwidth. Back it off to less frequent- every 60 seconds is probably sufficient.
I want to be reassured that I'm doing this the best practice way :
I have a list which order is changing on the server, therefore, I want every 20-30 sec. to perform a request to see if there were any changes in the order. So, I've created a Service which is bound to the Activity with the ListView, and the service every 20-30 sec. performs a request with an AsyncTask.
I chose to perform it with a Service because I want the list to be updated constantly, even when the application is in the background, And the AsyncTask is because I don't want it to be performed on the main thread.
Is this the right way to do it?
Thank you in advance,
Dan.
It will work, but your app will do a lot of unnecessary work. This will affect battery life. Besides that, according to documentation, if you use device radio, it stays full-powered at least for 20 seconds, which is also no good for battery. You have the following options:
Use Google Cloud Messaging. It will allow you to perform update only when this is really necessary.
If you don't want or cannot use GCM, follow this guide to optimize network access. Start with increasing the update interval (to 4 minutes at least).