Checking server every 5 minutes [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I saw 2 approaches to check a server in Android every X time, therefore I want to ask which way is better.
My application is requesting a HTML page from a server.
First option, is to run a service with sleep time of 5 minutes.
Second option, to set an alarm manager with interval time of 5 minutes that triggers a broadcast reciver.
Glad if you can tell me which way is better, or if there is a better way.
Thank you.

I would suggest using AlarmManager and set alarms every 5 minutes and use a BroadcastReceiver to get the message.
My reason is that when you run your service in the background, if OS needs more resources it will kill your service and get its resources for other apps but with Alarms you reduce the risk of killing your app.
Regarding checking server, you should consult this manual. just a single poll request to the server will make your radio active for at least 30s and will consume your battery. So maybe you should reconsider your intervals or even your strategy.
One other note: If you are just checking the server for new data and want to be informed if something has changed you can use Cloud Messaging. You can do most of the processing in the cloud and just send the important data back to the device(s). It is more efficient

i agree with #Pooya. Also you should implement a boot receiver so that your alarm will be set if the phone is rebooted. Here is the sample app that i downloaded from http://developer.android.com/shareables/training/Scheduler.zip

Related

Is it not possible to have a code in the background who will be called every 24h? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
In my application I do a ranking of the points of a user. However, I do the calculation of my ranking just every 24 hours. My problem is that I do not know where I should put the code of the calculation without disturbing the user.
Is it not possible to have a code in the "background" who will be called every 24h? Because at the moment, the code for the calculation is called when the first user uses my app after 24h, but then the user has to wait some minutes until the calculation is over. My data of every user is saved with Firebase.
Thanks in advance!
Edit April 22, 2019:
Recently, Google Cloud released Cloud Scheduler, which allows you to schedule HTTP requests or Cloud Pub/Sub messages to functions that you deploy.
This new service works also very well with Firebase and for that I recommend you read an excellent article writen by Doug Stevenson on the Firebase blog named Scheduling Cloud Functions for Firebase (cron).
Is it not possible to have a code in the "background" who will be called every 24h?
Yes, it is possible. In this case, you should write a function in Cloud Functions for Firebase and call it whenever you needed. If you want to be triggred every 24 hours, use the follwing service:
https://cron-job.org/en/
This means that you can do that particular calculation even if the user has the app closed. For a code example, please see Frank van Puffelen's answer from the following post:
Cloud Functions for Firebase trigger on time?
For your case I'd recommend using default Android tools for scheduling jobs. You can try using a new WorkManager or just a JobScheduler. Also you can try digging into this article to get more information.

Continuous Android Background Service [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm interested in finding out whether it's possible to implement the following:
1) Run a service every 24 hours at a specified time.
2) Launch a method from the service that does something.
I'm assuming that I will have to run a background service, but I don't want the user to have to initiate it in any way. It should be running constantly from the moment the user logs in the first time, and cannot be disabled. Could I use Android AlarmManager (https://developer.android.com/reference/android/app/AlarmManager.html) and disable the alarm response?
You can request the permission for android.permission.RECEIVE_BOOT_COMPLETED and register a BroadcastReceiver for it. But you can not enforce this onto the user, he may stop the app and the service forcefully.
You don't have to notify the user if a service is running or starting, this is optional but not advisable e.g. unknown battery / network consumption.
Instead of going to Alaram Manager you can use handler to perform your task every 24 hours...And the RECEIVE_BOOT_COMPLETED would only be triggered if the device is rebooted, hence start the service also during login...Whatever be the service it would be destroyed manually...

Android: Job Scheduler for planner [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I found out about Job Scheluder but I can't understand for what I can use it.
Is it suit to create planner, for example?
I want to launch notification in a month in setted day and time.
Is Job Scheluder good solution for that or I should choose something else? I want to find a good lib for this task.
No. JobScheduler is for short term background tasks like when you want to download a file in the near future and want the system to find an ideal time for you. E.g. you want to download a big update file and want the device to be plugged in and have wifi rather then when the user is low on battery and wouldn't want to loose the last bits of energy for some file.
https://www.youtube.com/watch?v=QdINLG5QrJc explains
http://developer.android.com/reference/android/app/job/JobInfo.html are the options you have to specify when you want your job to execute.
When you want to launch notifications at certain times look for AlarmManager http://developer.android.com/training/scheduling/alarms.html

Android Design Best Practice [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am in the process of designing my first Android application and have a best practices/design question. So not necessarily looking for code, but for someone to lead me in the right direction as far as research goes.
I am looking to have an application where a user kicks off a timer. When that timer has expired, the application will run some code. I need the timer to continue to run even when the user closes the application and/or reboots the phone. So even if the phone dies, once it is charged and turned back on I need my application to kick off and recognize the timer has expired and run some code or continue counting down (essentially checking to see if a particular date and time has been reached). In addition, I want the user to be able to re-launch the application and end the timer pre-maturely if desired.
I thought I was on the right track by creating a local service in a seperate process but further research shows that may not be best practice and to look into alarm manager with broadcast. So my question to the masses...what route should I be tacking to achieve my goal?
Thoughts/Suggestions? Thanks in advance!!!
I thought I was on the right track by creating a local service in a seperate process
That is an anti-pattern (everlasting service) on top of an anti-pattern (separate process).
what route should I be tacking to achieve my goal?
Use AlarmManager, plus a BOOT_COMPLETED BroadcastReceiver. The BroadcastReceiver can detect missed events, plus set up a fresh AlarmManager schedule.

Test connection speed with Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a Java server and Java client I'm interested is there any way to test with java the performance speed and the delay time between them?
I don't want to use the standard ping.
Not sure how Effective it would be, but I think of this approach :
send some specific amount of data to server, from server send back the time the uploading is finished then calculate the time required to send the data. Result Will Be U/L time. Do the same for the D/L time. Request data from server, server should respond you with data along with the time the first bit was sent from the server. When All data is downloaded, calculate your D/L time.
Important thing to note here is, there may be the different instance of time, at server & client (& most possibly there would be), you need to Sync you time with the server time first.
send some specific amount of data to server, send back the data. Calculate the total time required. It will be your D/L + U/L time. Since the calculation would be at client only no time syncing is required here.

Categories

Resources