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...
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
One of the pages in my app needs to be the same as the native messaging app. That is have all of the uses messages and be able to send and receive sms messages.
There is no way. The only method you can try is to launch the Messaging App, but I dont think that this is what you want.
This is not possible. How ever you can launch a share intent if you want to share data from your app to the other app. Other than that there is nothing you can do to include it in your app.
You can't do it. You can launch the messaging app. But on modern Android, only the default SMS app can receive SMS messages. Not to mention- every phone out there has a different "native SMS app" on it, so there's no way to make an app look like it.
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 5 years ago.
Improve this question
I am developing an android app using firebase. I want to create an event that will automatically remind the user base on user deadline date input choice. For example: user input date from:? to:? and date will be stored into firebase database and user will be receiving reminders until the deadline end. Is there anyway to set an automatic notification from the firebase server? Can anyone point me to the right direction. thanks
If you mean automatic push notification from server, sure it can be done easily with cloud functions and cron jobs. There are many ways to do it
Method 1 :
First, create cloud function with http event to check which event will need to be remindered. And do push notification using FCM token of the user.
Second, make a cron job that call that function daily, or hourly. See detail example here for more explanations.
Method 2 :
Same with above, but using pub-sub event. And the cron job using google app engine. The step by step guide, can be found here
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 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.