Using timed events in BlackBerry - events

is it possible to fire up an event at a specified time interval in BlackBerry? I'm looking for something similar to AlarmManager class in Android (if anyone is familiar with it).
The goal is to is to run some code, even when the application is not in foreground and without it gaining foreground "focus". Preferably it should be possible to fire the event even if the app was killed by system or by phone reboot (I do not know the details about killing apps at this OS, I'm beginning development now).
I would prefer not to write a background process for this task as it is going to be fired every few hours (I think it would be a waste of battery to use a background task for a simple alarm-like event).
I've looked around a lot, but I cannot find any satisfying solution.
cheers,
kajman

The Timer and TimerTask classes are useful for running a task on a schedule. Take a look at the APIs here:
http://www.blackberry.com/developers/docs/7.0.0api/java/util/Timer.html
The Timer will create its own Thread and sleep until it has a task to run. It would involve having a background task running but it wouldn't be using an CPU or battery if it is just waiting.
If you don't want a Thread running all of the time you can use the ApplicationManager class to schedule your application to start later.
You can also configure your app to run on start up. The OS generally won't kill your apps unless you have a coding error. RIM refers to this as the Always-On Experience in their Super App document:
http://docs.blackberry.com/en/developers/deliverables/23567/Always_on_1380986_11.jsp#Keeping_the_app_running_1381022_11

Related

Scheduled task with UI need delay to work properly

I'm trying to launch a application with a UI at login on windows, using the task scheduler. I've came across some inconsistencies with this, sometimes the UI will launch properly, other time it wouldn't. By adding a delay to the task, I can safely make it executed ON MY COMPUTER.
How can I ensure this correct behavior on any given computer?
Is it something to do with Windows UI not being "ready" or something like this ?
Any resource would be appreciated !

Is there a api function for a MacOS Store based application to start itself at a certain time

Under Windows i use the Task Scheduler, under linux cron job to start an application at a certain time, even if the cron job would work on MacOS, i wonder if there is a apple conform way to start my application at certain times and to start the computer from hibernation.
I know that cron jobs would work, but i doubt that this would ever pass its way through a apple review.
The reason for this question is that the application is working a tv player with the ability to record DVB transmissions. I dislike the idea to "force" the user to keep the program running in background.

UWP apps running background tasks when the app is closed

I want to run a background task for every 10 mins.As the UWP app will not always be opened.Is there a way to run a background task even when the app is closed(Not Running State)?
If the answer is NO,
Is there any another way other than Windows Services?
You can create BackgroundTask which run at the most every 15 minutes not less than that in UWP apps. for more details you can check this source.
Is there a way to run a background task even when the app is
closed(Not Running State)?
According to this document:
You can use background tasks to provide functionality when your app is
suspended or not running.
The 'not running' state in UWP is described in more detail here. It reads:
An app could be in this state because it hasn't been launched since
the last time the user rebooted or logged in. It can also be in this
state if it was running but then crashed, or because the user closed
it earlier.
This implies that the app simply needs to run once after installation to be able to successfully register a background task, which can then run even after your app is closed.
I want to run a background task for every 10 mins
Not sure I'm interpreting this correctly but I assume you mean you want to run some bit of code every 10 mins while your app is not running. Well there are two way that I can think of to achieve this.
Method 1:
While background tasks are meant to be very short-lived tasks, they may even be made to run indefinitely if:
extendedBackgroundTaskTime capability is added as a restricted
capability in your app's manifest file
Using this technique along with a simple timer mechanism would achieve the desired result.
Method 2 (more complicated but keeps background tasks short-lived):
Setup a DatagramSocket to a remote server which sends some data every 10 mins and register your background task with a SocketActivityTrigger.

Automatically force quit frozen applications in OSX maybe using a ruby script?

I built an application using openframeworks that is live 24/7 on a kiosk. Every now and then (every few weeks) it will randomly go unresponsive and I still can't get to the bottom of it because it's so random and infrequent it is hard to debug.
I wrote a ruby script that looks for the application running and if it doesn't exist it will start it up. This works in all cases where the application name doesn't show up in activity monitor. Meaning if the app crashes and completely force quits itself or something. It works just fine.
However, if the app just freezes and goes unresponsive (red highlight in activity monitor) the app doesn't quit out completely unless I force quit manually. Is there some kind of script I can write to look for all "unresponsive apps/processes" every few seconds and force quits them automatically? That way my app launcher script will be able to detect that the app isn't running and boot it up again.
I suggest you look at Monit because it's solid, well tested, well documented, and easy to learn.
If you still want to write your own monitoring script, Monit is a good example to follow.
The most reliable way to detect an unresponsive app is to have a "vital sign" which is a generic term for a signal that an app emit to prove it's healthy. Some people call this a "pulse" or "heartbeat" or "brainwave". Your external script watches the vital sign. If your external script sees the vital sign flatline, then the script takes action to cure the app or restart it.
An alternate way is to have a "ping" which is a generic term for your external script sending a signal to the app or the system, then listening for a reply. You can use tools such as the Unix ps command for processes, or AppleScript Activity Monitor. As far as I know, these do a pretty good job of catching common cases, but have trouble catching apps that are soaking up resources, such as being caught in endless loops.

How UI Threading in android works?

If an app is brought to the background what happens to the UI Thread which was running this app?
Will it sleep or get killed?
When the app is back to foreground will the same thread be notified or a new thread will created and associated with the app instance?
I don't know specifically, but you should always program with the possibility that your Activity may be killed at any time that it is not in the foreground. Whether that involves killing the thread every time it enters the background, or causing the thread to sleep and then killing it if the Activity is killed, I don't know. In any case, you must assume it can and will happen, and program accordingly.
It depends on the memory situation. When your application goes into the background, it generally stays running initially. Android does not sleep your thread. It is up to you to stop updating your UI and performing calculations in on onPause.
However in low memory situations Android might kill application when it's the background (especially if you haven't been nice and are using up a load of resources). For this reason you should always save any persistant data in onPause.

Resources