Is there a way to run one of my apps functions after every minute in blackberry 10? [duplicate] - listener

I searched the internet but there is very little documentation available on BlackBerry 10 development. Is there something in BlackBerry 10 that allows you to run a function forever after specified intervals of time? Like there is NSTimer in iPhone/Objective-C that can run a function after every x minutes or so.

As pointed by #Sorry_Boss, you can use QTimer on C++ code. If you want to do that in QML, you can also register it for use in QML in the constructor of your app class, like this:
qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer");
Then, you can import it in your QML file:
import my.library 1.0
... and use it as an attached object to another component:
attachedObjects: [
QTimer {
id: timer
interval: 1000 // 1 second
onTimeOut {
// do something
}
}
]

Use QTimer.
QTimer timer = new QTimer(this);
timer->start(intervalTime);
Connect timeout signal of timer with your function.
QObject::connect(timer, SIGNAL(timeout()), this,
SLOT(yourFunction()));

Yes this can be done with QTimer
In cpp
QTimer *timer= new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
void AppName::update(){
//Do operation on timeout
}

As a more general answer, because you will likely run into the same problem again, you have to treat BB10 as a completely different operating system and development environment because it is. Unlike the old environment though, the documentation is actually quite good. For example finding information on timers is as simple as going to the Cascades documentation site, selecting API Reference and typing 'timer' into the filter text box.
You will also find a wealth of help in the form of sample applications and general documentation and guidelines.

Related

stable-baseline3, gym, train while also step/predict

With stable-baselines3 given an agent, we can call "action = agent.predict(obs)". And then with Gym, this would be "new_obs, reward, done, info = env.step(action)". (more or less, maybe missed an input or an output).
We also have "agent.learn(10_000)" as an example, yet here we're less involved in the process and don't call the environment.
Looking for a way to train the agent while still calling "env.step". If you wander why, just trying to implement self play (agent and a previous version of it) playing with one environment (for example turns play as Chess).
WKR, Oren.
But why do you need it? If you take a look at the implementation of any learn method, you will see it is nothing more than an iteration over time steps calling collect_rollouts and train with some additional logging and setup at the beginning for, e.g., further saving the agent etc. Your env.step is called inside collect_rollouts.
I'd better suggest you to write a callback based on CheckpointCallback, which saves your agent (model) after N training steps and then attach this callback to your learn call. In your environment you could instantiate each N steps a "new previous" version of your model by calling ModelClass.load(file) on the file saved by a callback, so that finally you would be able to select actions of the other player using a self-play in your environment

How should RenderTargetBitmap be used?

In a Windows Universal App (WinRT) application, I am trying to capture a bitmap image of the current page (or a portion of it).
A google search indicated that I should use the class Windows::UI::Xaml::Media::Imaging::RenderTargetBitmap (more specifically its method RenderAsync() ) to capture the screen.
In a small sample application, I thus added this code (C++) :
auto pclRenderTargetBitmap = ref new Windows::UI::Xaml::Media::Imaging::RenderTargetBitmap;
Concurrency::create_task(pclRenderTargetBitmap->RenderAsync(pclElem,100,100)).then([&]() {
// handling code here
});
(pclElem is a FrameworkElement, more specifically a canvas, and is not null)
When I execute this code, the task is indeed created, but the lambda in the "then" is never called. It's as if RenderAsync() never terminates.
Does anyone have any experience with using this function in C++ ? What am I missing ?
Thanks for your answers.
Thanks to Andy Rich for his answer.
The problem was that the pclRenderTargetBitmap was going out of scope.
This can be solved by passing the lambda parameters by value :
auto pclRenderTargetBitmap = ref new Windows::UI::Xaml::Media::Imaging::RenderTargetBitmap;
Concurrency::create_task(pclRenderTargetBitmap->RenderAsync(pclElem,100,100)).then([=]() {
// handling code here
});

Can an embedded cocos2d-js app call back out to c++?

I'm researching the possibility of using cocos2d-js by embedding it as a view inside an existing iOS app. In order to make this work, I'm going to need 2-way communication between cocos2d and the surrounding application.
After some initial investigation, I have determined that it is possible to call in to cocos using ScriptingCore:
ScriptingCore* sc = ScriptingCore::getInstance();
jsval outVal;
sc->evalString("function()", &outVal);
My question, then, is around doing the reverse. It is possible to (e.g. in response to user input) call back out of cocos2d-js to C++? Ideally, there would be a way to register a callback with ScriptingCore which could be invoked from JavaScript.
I believe it can be done, but I have not tried myself, nor can I find a good and concise example.
All I can do is point you at SuperSuraccoon's Bluetooth example and it's git page, which apparently does both ways communication between C++ and JS code.

Flash ActionScript - Trace from background Worker

Is it possible at all, or traces are part of the API which is not avalible from background Worker?
Consider this code:
public class Main extends Sprite {
public function Main(container : DisplayObjectContainer = null)
{
if(Worker.current.isPrimordial) {
trace("isPrimordial");
var m_worker : Worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes);
m_worker.start();
}
else {
trace("is NOT Primordial");
}
}
The string "is NOT Primordial" does not appear, however I do see that m_worker.state is "WorkerState.RUNNING".
Some UPDATE: The main thread works and racts to events, however it appears like the backgroung worker does not start until I desconnect the debugger.
And if it is possible, how do I setup the fdb to show these logs?
PS. Im using flash standalone debug player 13 with latest FDT and Apache Flex 4.12.1 SDK.
Ok, so the results for now are:
The background thread (Worker) can write traces with no problems at all if the debugger is not attached, for example if we are using flashlog.txt for the output (output to file).
What is required is: flash debug player (me used v. 14 stand alone and firefox versions).
The setup for using text file as output discussed here:
http://helpx.adobe.com/flash-player/kb/configure-debugger-version-flash-player.html
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fc9.html
Correct location of mm.cfg on modern operating systems (and not on Win95!) discussed here:
https://forums.adobe.com/thread/1218258
For me the output to file started to work only after the flashlog.txt file was created by some 3rd party tool (I used Vizzy), but probably it is a permission problem of flasho n windows 8 and the file just can be created manually.
Detailed discussion of the flash traces topic (althoug a little old, but mostly still relevant) is here:
See trace() of Flash when running in browser
Thanks everyone for help.
Create a static Log class that output it's log to trace. Use this log class in your main thread and in your worker. Only the main thread log definition will be used allowing to trace from anywhere.

Adobe AIR Sqlite assync transactions

Here is the problem that I want to implement a solution, I have some data that needs to be writen in a database,data comes from network and it could arrive in "parallel", also for performance reasons the code is using async connection. The problem is that I have some bugs in my implementation ,I want to rewrite this code so it also uses transactions and rolloback,handle all possible errors and the code should be clean and easy to understand.
I am unable to find example code to read to get inspired or something to use directly, looking on what others done would help a lot.
So anyone know or has such example code?
I think I need to write some code that will allow me to chain this methods :begin->execute->commit->end transaction and in case of errors rollback
Update
what I want to find or implement is something like
Update2 so where things get confusing is when you want to insert an array of stuff, you will need to use a loop and then use the execute method async, and then when it succeds insert the next element and so on, this makes it a little more complicated especialy if I want to abstract this ito have all this section of code in a single place and not all over my code.
function executeAssyncAsTransaction(statement:SqlStatement,responder:Responder):void{
//step 1 begin transaction
//step 2 execute
//step 3 commit
//step 4 end transaction
//step 5 handle errors and rollback
//use responders above no event listeners
}
I think I know how to implement this but I know that there is a chance I do it wrong (my current implementation that is in production crashes sometimes on some machines so I I know is hard to write 100% error free code)
I am, also thinking to implement a queue that will store my statements if needed(if database is busy) so I don't get an error and have to try again later
Use event listeners, error and callback functions in Adobe Air for JavaScript like this:
var conn = new air.SQLConnection();
conn.addEventListener(air.SQLEvent.OPEN, openHandler);
conn.addEventListener(air.SQLErrorEvent.ERROR, errorHandler);
// The database file is in the application storage directory
var folder = air.File.applicationStorageDirectory;
var dbFile = folder.resolvePath("DBSample.db");
conn.openAsync(dbFile);
function openHandler(event)
{
air.trace("the database was created successfully");
}
function errorHandler(event)
{
air.trace("Error message:", event.error.message);
air.trace("Details:", event.error.details);
}
For ActionScript read these ressources:
http://de.slideshare.net/peterelst/introduction-to-sqlite-in-adobe-air-1627545