How to schedule my android app to do something every hour - java

I want my app to access database every hour and read next record from the table then update desctop widget and send notification. I know that there is AlarmManager which I can use to register my Intents but they are deleted when the phone is turned off or rebooted.
Is there any other android class/service that I would update my application continuously even when I reboot my phone?
Thanks,

take a look at the demo applications provided with android sdk
http://developer.android.com/samples/RepeatingAlarm/index.html
the look at AlarmService_Service for the implementation of the service once the alarm has been triggered

put all of the background tasks you want to do in your app in Services which perform tasks in the background. In the service you should be able to define a timer that causes whatever updates you want to occur every x hours.
In the onCreate() of the widget, start the service. onCreate() is called every time that the widget comes to life (such as when the phone starts if it is on the home screen) and will therefore guarantee that the Service is always running.
Hope this was helpful.

Just for the sake of completness, I am linking here the official docs, where the issue of the rebooting is adressed.
http://developer.android.com/training/scheduling/alarms.html#boot

Related

Java - android - change activity of app while running in the background

I'm developing an Android app with several types of alarms and triggers.
One of these alarms trigger if you stop moving (GPS tracking) while it's active.
Now, when the app runs in the background when this triggers the client doesn't update when you switch back in, and the only notification received is a push-notification from the backend service. If I enter through the notification, the client loads the alarm correctly.
The code base is quite extensive, and due to time and resources it would be best to avoid huge refactoring tasks.
Is there an easy way to make the app go from Activity A to Activity B when it's running in the background?
You cannot change the current Activity in the background without bringing the app to the foreground (using startActivity()). However, you can surely tell the app that when it is brought to the foreground it should start a certain Activity or rearrange the back stack or whatever.
Post some of the code and maybe we can help more.

Launch app on background for manage notification

Hello I have trouble with manage notification
I have app with control weather in some place (when change I want build notification) one a day control it's okay, for example on 10:00 and ecery day, If I can run one methot/activity/class for control weather and launch notification if need..
I have only simple notofication from developer android.
and I have troubble for find some "advice" with my problem.. i find some with use firebase, but thing so it's not for me.
Thanks
You need to use a Service (which is basically an Activity without an interface). They have a Context and you can send notifications from there.
Have a look here.

Notifications when the app is turned off

I wonder if it is possible to have notifications show up even if the app is turned off.
say for example I have an app and I set some kind of notification for 13.00 the next day and then turn the app off or restart my phone or something.
Is it possible to still get a notification in the notification bar with some text that starts the app or do the app need to run in the background to be able to use notifications?
if it is possible, what is the best way to do this? (get a notification at a certain time that starts the app) and if not, how do you recommend doing notifications?
The type of notifcations I want to do are reminder notifications.
thanks for all help!
A combination of AlarmManager and Service will help you to perform the task you are looking for, I had performed this thing.Check out the android tutorials for it.
What you're looking for is a background service. See this Android Services tutorial.
In the background service, your app should check periodically and when necessary, create and issue new notifications. See this Android Notifications tutorial.
The background service can be set to automatically start when the phone is restarted, and to re-issue any uncleared notification again.
Many apps such as Gmail already do this. Although you must be careful in resource usage or Android might kill your service.

Multiple Notifications from Foreground service Android

I'm working on an application where I need to show notifications 5 times a day ...from a foreground service..the purpose of using the foreground services is to be able to display notification even if the
application is closed . so I want to start the service as applications starts and schedule its notification timing accordingly I have tried using the snippet provided on android developers forum but its not working for me ... any help and sample code is highly appreciated Thanks
If the notifications are to be fired at a fixed time, you may not need a foreground service. It is a bad idea to keep a service running just to show notifications. Schedule those five times using an AlarmManager. You can find tutorial for it in google.
You would need to schedule alarms one by one. Foe ex..when alarm manager wakes your app the first time , then schedule a second alarm and son on.. You may not be able to set 5 concurrent alarm schedules. Do it one by one..

How to get an androidapp to do something at a certain time of the day

I would like to write my first Android app using Java and I was wondering how to schedule the app to perform a certain task, or call a method at a user-specified time of day. Also, I would like this to happen without having to keep the app constantly running in the background.
Is there a way to have the user set up a time at which the Android system wakes the app to do what it's supposed to do? Or do I have to have the app load on startup and constantly running in the background?
Yes, it's called an Alarm. Have a look at AlarmManager.

Categories

Resources