can AlarmManager(alarm.setRepeating) work in case of phone restart - Android - android

I came in to scenario that I want to trigger service on specific time.
What I Know is...
I need use AlarmManager, and I found this question in hear, Using Alarmmanager to start a service at specific time. Now, I am able to start service on specific time.
Now question I have is... I need 24H interval to start service. now What happens if the phone restart. Is it going to start service again?
How can I make this thing happen?
Please help me with this
Thank you

No.. It wont.. You need to set it again when phone Boots .. something like this

You'll need to register a BroadcastReceiver that can receive the BOOT_COMPLETED message so it receives a message when the phone reboots...
Read this article!
http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/

Related

Unable to start Service after App startup

Hello all i want location updates when my app is triggered first and after even it is killed i want my service to run i tried broadcast receiver for this purpose but it run on phone reboot Can anybody guide me to the right direction? Thanks
depending on the layout of your code, I believe it might be as easy as making the app perform the location update request on onResume while leaving onPause blank to test if it works for what you want. At least if I understood you correctly, that's what worked for me but it might drain your battery if you are using some power demanding location provider like GPS. And about your service to survive reboot I'm not really acquainted on that topic but from a quick read, indeed using broadcast receiver and listening for BOOT_COMPLETED to set off an intent.setAction declared after onCreate on your MainActivity should do it, but haven't tested that myself yet. Anyhow, it would be best if you can post the code you're working with so that others can see exactly what you have so far and be more helpful.
Hope it helps

Get Location updates in background without running Service in Android

I want to fetch the current Location of the user in background. I know how it can be done using Service in Android. But I would like to know is there any possibilities to get user Location without running service. Like using BroadcastReceiver or anything? I'm just trying to avoid running Service to fetch Location.
For Example I referred this link. But I couldn't follow how to do like this.
Any help will be appreciated. Correct me in case I'm asking anything wrong.
EDIT: Oh, I think in the above link he is using Service to get the Location. So I think it's not possible to get location in background without running a Service. Still suggestions are welcomed.
You Should Implement a BroadcastReceiver that receives alarm every 2 hours. That alarm is Set by Your Activity.
When the alarm is triggered by your System, Broadcast Receiver receives it, Executes Your Process in BroadCastReceiver.
This is what i can think of.

Android Service is Quiting in Android 2.3.3

I have Android service to run and send email every 9 mins but after some cycles it quits. this app is also installed in my Android froyo but it works good for more than 2months now.. I can see the logs in logcat that the service quits but my problem is I cannot understand what does it mean.. Can someone help me with this? Thanks!! any help would be appreciated...
here is my source code:
https://gist.github.com/77a40ac93cd311acb56c
Logcat logs:
https://gist.github.com/dd3ab385d79253fac632
The point behind using AlarmManager is so that your service only needs to be in memory when it is doing actual work, and can go away in between AlarmManager events. You have managed to not do that, and therefore your code will not work reliably.
If you want to "send email every 9 mins", you should:
Move the BroadcastReceiver to be a public Java class, registered in the manifest via a <receiver> element, and remove the registerReceiver()/unregisterReceiver() stuff.
Switch your service to be an IntentService, so you get a background thread (which you need for your work, but your current code lacks) and so the service can automatically shut down when there is no more work to be done.
Add in the logic for the WakeLock that you will need since you are using a _WAKEUP-style alarm. You could combine this and the previous steps by switching to my WakefulIntentService, if you wish.
Deal with the case where the user reboots the device, if you want your alarms to continue after the reboot, such as by scheduling them again via an ACTION_BOOT_COMPLETED BroadcastReceiver.

What use to make reminder app?

I want to write reminder. What i need to use? Make service app or just standart app runing in background or another way?
Thanks for replys!
What I really liked about this question is you asked about the idea for the app that you want to implement. You didn't ask for code.
I would suggest that you should make an app which should have a broadcast receiver, but still it should have service that runs in background.
The service will check the current time with your reminder time. A broadcast receiver is required to listen to startup broadcast, because you need to start your app as soon as your handset starts.
Have a look at this.
Have a look at the AlarmManager. It allows you to schedule your application to be run at some point in the future.

Updating weather info, should I use alarm and/or a service?

I am having some design techniques about How shall I schedule a code to retrieve the weather info?
Should I use alarms to retrieve the weather each 10 minutes?
And do I need to run a service for this? Or just put the code in the Broadcastreceiver and start when the alarm fired?
This is a good question. Yes, you will need to put this code in either a service or broadcastreceiver because when and activity loses focus (meaning the user is using a different app or the phone is asleep) they pause and/or close. However, i have no experience with either Services or Broadcastrecievers, so that is as much as i can tell you.

Categories

Resources