I am an ionic2 beginner.
I need check my app is foreground or background currently running.
I refer this https://ionicframework.com/docs/v2/native/local-notifications/
I need notification received only at app is run on background.
You can use pause and resume Cordova events.
Subscribe your functions to them (taken from the link) :
document.addEventListener("pause", onPause, false);
function onPause() {
// Handle the pause event
}
document.addEventListener("resume", onResume, false);
function onResume() {
// Handle the resume event
}
Related
I create an app using MFC Framework that auto hide on startup, and if I press SHIFT+W then it shows the Windows.
I inherited the function PreTranslateMessage() like that:
BOOL CTestAppDlg::PreTranslateMessage(MSG* pMsg){
if (pMsg->message == WM_KEYDOWN){
if (pMsg->wParam == 0x57){
if (GetKeyState(VK_SHIFT) & 0x8000) {
ShowWindow(SW_SHOW);
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
But this function only catches the keypresses if MFC App is active. So if this App is hide in OnPaint() function with ShowWindow(SW_HIDE) then it cannot catch the SHIFT+W to show windows normally. How can I do for it? Thank all
As explained under Keyboard Focus and Activation:
The system posts keyboard messages to the message queue of the foreground thread that created the window with the keyboard focus.
As a window gets hidden the system transfers keyboard focus to the next eligible window, causing your window to no longer receive keyboard input as you observed.
There are several ways to observe input globally. In this case the most appropriate solution is to just call RegisterHotKey and provide a CWnd::OnHotKey implementation for the respective receiver of the WM_HOTKEY message.
I have a wxWidgets windows application, I am launching annother application upon click a certain button on
my appication, This new launched application behaves like to modal window and my application is sent back, But
when user use Alt+Tab or click my appliction icon, My application comes to front, whereas child application
which is already opened should have been shown
I figured how to bring an application to front, Now i would like to know if i can set a callback to parent application
which will be called whenever application is activated (either through Alt+Tab or task bar icon or any other way),
So i can bring my child application to front at this time.Is there a windwos API for this?
WM_ACTIVATE
Sent to both the window being activated and the window being
deactivated. If the windows use the same input queue, the message is
sent synchronously, first to the window procedure of the top-level
window being deactivated, then to the window procedure of the
top-level window being activated. If the windows use different input
queues, the message is sent asynchronously, so the window is activated
immediately.
case WM_ACTIVATE:
{
// test if window is being activated
if(LOWORD(wParam)!=WA_INACTIVE)
{
// application is being activated
}
else
{
// application is being deactivated
}
}
break;
EDIT:
If you want to use a hook to monitor whether the window is switched, you can refer to this link.
Capture switch window event (window focus) (Alt+TAB)
This question already has answers here:
Exit application in iOS 4.0
(11 answers)
Closed 6 years ago.
I have some problems with my interface when I open my app, go to background and finally return to foreground. So I want to force my app to start the app always, when I came back from background.
I saw that Clash Royale game is working like that.
I am developing with swift 3
I don't know exactly what your Home Page looks like that you want to load up after returning from the background but you should be able to use the functions in the AppDelegate to be able to set values and load up Scenes or Views as needed when returning from the background state or to be able to set the desired view as the app gets closed down.
Here is a list of the functions that are already built into the AppDelegate.
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
As far as I know there are four types of Touch Type in Blackberry 10-
Down
Move
Up
Cancel
In slot onTouch() I check for these four type of events and do some of my task there. Like below:
if (event->isDown())
{
// implementing my task
}
if (event->isUp())
{
// implementing my task
}
if (event->isMove())
{
// implementing my task
}
if (event->isCancel())
{
// implementing my task
}
So, what is my problem? While executing some of my task in isUp() codeblock and at the same time I touch the screen. But I am not getting any isDown() event in my code while my isUp() is running. After finishing the task inside isUp() then I get the isDown event.
My target is to get isDown() event while I am touching my screen to stop execution inside isUp().
How can I implement this into Blackberry 10?
Thanks in advance.
I recommand to read this interesting blog article, to understand how UI rendering thread discuss with the application thread:
http://devblog.blackberry.com/2012/09/cascades-custom-ui/
If your procces in "isUp" is this long, you have no other choice than doing it in a thread, and terminate the thread when "isDown" is called:
http://developer.blackberry.com/cascades/reference/qthread.html#terminate
I tried to find answer, but I didn't find it.
I want to do something like this:
when I click button, I would like it to repeat actions till another button is clicked
I have something like this:
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
if(pole!=NULL){
pole->przesun_lidera(pole->wladca);
pole->rozstaw();
pole->rysuj_plansze();
}
}
and I want to repeat actions within "if", until I click another button.
Could someone tell me, how can I achieve this?
I think you have two possibilities here. One is to make a thread and execute your code in it until a condition, set by another button is set. Another possibility is to allow the message pump to process messages while inside the loop, by calling ProcessMessages(), e.g.
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
condition = false;
while( !condition && pole!=NULL){
pole->przesun_lidera(pole->wladca);
pole->rozstaw();
pole->rysuj_plansze();
Application->ProcessMessages();
Sleep(1); // don't be a processor hog
}
}
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
condition = true;
}
You will need to have a function that is executed in the "background".
Windows is an event driven system. Your functions are only activated when Windows receives an event. My understanding is that you want something to happen while waiting for a specific event (button press) to occur. This time between events is "background" time.
One idea is to have Windows execute your function while it is waiting. Search the web for "Windows spin wait". This will give you information on how to "hook" a function to the background or spin-wait loop.
You may also want to create another thread as a background task. Have your first button click turn on the background thread. The background thread will execute until a semaphore or wait-object is set. The second button press will set this semaphore / wait-object, informing the background task to stop. There are similar methods, but this is the foundation of the issue.