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.
Related
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...
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
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
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 4 years ago.
Improve this question
I have working on developing scheduling application as a start up and application take some time to complete. during the scheduling process I cannot use service calls to load data, because it will reduce the performance. It may cause to terminate the process if data access failed.
So I need to load required data before starting the scheduling process and discard that data after completing the schedule. This is some kind of caching but it doesn't need all the features in caching like check for expiries, discard expiries update new changes etc. Need to load once a month only for the scheduling.
So can somebody tell me what is the best design pattern to handle that situation. Thanks
Well that's a place for Prototype pattern, but you should also consider using some caching framework and just disable all fancy features like expiration, pinning, etc.
In the test automation patterns such
need to load required data before starting the scheduling process and discard that data after completing the schedule.
is called fixtures. So what you need can be achieved with setUp() and tearDown() functionality. Generally a Setup Decorator will do just fine. It'll "bracket" the execution of the entire scheduling process with a set of matching setUp and tearDown "book ends".
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
To illustrate the problem, let's say I want to write an app that allows call recording.
I know that I can't record the caller and called audio due to the OS restrictions on the systems current phone activity. The only way to pass this restriction is by "hacking" the OS code, which will require in the minimum a root access from my users.
So, is it possible not to hack the android phone activity, but to write one of my own, that when an incoming call intent rises, the user will be able to choose which activity to launch ?
If so, a few pointers would be nice :)
Thanks.
I could be wrong, but I have not seen any phone recorders that work across all platforms because it seems to be a hardware kernel level issue and not an OS/API issue.
As far as replacing system applications you have to root the phone to do that anyway, unless I am misunderstanding what you are asking.
Of course all the android source is available so you can poke around in that all you want and see if there is anything that has been missed
You can define an activity that responds to the Intent.ACTION_CALL intent, which will cause the user to be prompted to choose between your app and Phone when they do something that initiate dialing a number (the new Skype app does this, for instance).
However, there are some big limitations. You will not be able to intercept incoming calls. And you will not be able to access the API to actually make a call with the phone (again, think of Skype--they handle the intent by placing a call through their own service, not through the Phone's modem).