How to detect application shutdown on Gluon mobile? - gluon-mobile

I would like to run some Java code when users stop the application on mobiles, for example to save some data when they swipe up the app. I tried Runtime.getRuntime().addShutdownHook(Runnable) but the runnable is not called. I looked at Gluon attach lifecycle module with LifecycleService.addListener(LifecycleEvent, Runnable) but LifecycleEvent only accepts PAUSE or RESUME, not STOP. So how can I achieve this?

Related

Difference in manual execution of running app in background and runAppInBackground() using appium

While executing runAppInBackground() for Android application through Appium the app gets restarted but when executed the same manually couldn't be able to reproduce the same. I Would like to deep dive into implementation of a runAppInBackground() method to reproduce the same issue in a manual way.
You need to look behind the code of runAppInBackground
From java client side (your test code) perspective, it is a single call to Appium server:
POST "/session/:sessionId/appium/app/background"
If you continue looking into where its implemented on server side, you finish with appium-android-driver function.
In short what it does:
Get current activity and package
Press physical Home button
Wait for time you provided as argument (seconds)
Bring up back in focus based on different conditions; from the code you can understand what activity is being started
Basically its a sequence of adb shell commands, that you can run from terminal.
My guess is that step 4 you did manually may differ from what Appium is doing: different activities/arguments for activity been called

Run python kivy application in "kiosk mode"

I've created a simple python application running in raspbian using kivy. The application runs already nicely in full screen mode. however I would like to be sure it cannot be interrupted with ctrl-c or any other command using the keyboard, and the application must never lose focus if something happens in the OS (for example some kind of dialog opens - I'm not sure if this actually can happen). I'd appreciate things that should be taken care of.
My app doesn't need to be bullet-proof, but it should endure a "casual user".
You can catch Ctrl+c or other signals with the signal module.
import signal
def signal_handler(signal, frame):
pass
signal.signal(signal.SIGINT, signal_handler)
This code prevent the user to exit by sending the SIGINT signal, corresponding to ctrl + c.
Other signals: https://unix.stackexchange.com/questions/317492/list-of-kill-signals

DOM ready event inside Electron how?

This is a silly question, but I could not find a clear answer on the web.
Do I need to listen to a special "dom-ready-event" if my app is running within a BrowserWindow in Electron? For instance in a Cordova/PhoneGap app I read you can start doing things after the deviceready event.
I would like to know how this is done in Electron? Is one of the following enough?
document.addEventListener("DOMContentLoaded", startApp);
window.addEventListener("load", startApp);
Thank you.
Cordova has deviceready because it has both native code and JavaScript code, and potentially JavaScript might run before the native code has finished loading.
You don't have the same problem in Electron. You have a main process (main.js) which creates your BrowserWindow, so by the time any client-side JavaScript is running, your main process has definitely already started because it was the thing that created your browser window in the first place!
Inside the browser window the same events fire as they would on a normal webpage. So if you wanted to, you could use DOMContentLoaded or load (for the difference see this article on MDN), just in the same way as you would for a regular web application. But you certainly don't need to before calling any of the Electron APIs.

AIR for Mobile: how to debug MultiTouch?

Is there any way to simulate touch events in ADL? If not, how do you properly debug an application that heavily relies on touch events?
Using a device seems to be the best way, though it also appears this overlaps a previous SO question that describes the same issue in the normal Android Emulator: Is there any way to test multi-touch on the Android Emulator?
Also with regard to code testing you can still write unit tests to test out your objects/methods and verify they have the appropriate input and output. If you're so inclined as to do so you could even have it dispatch events from UI components using code like
//in your code
Multitouch.inputMode=MultitouchInputMode.GESTURE;
someComponent.addEventListener(GestureEvent.GESTURE_TWO_FINGER_TAP, someHandler);
//and in your test
someComponent.dispatchEvent(new GestureEvent(GestureEvent.GESTURE_TWO_FINGER_TAP));
//verify appropriate change occured after a timeout or something of that nature
and should be able to get the appropriate reaction to the event.
more on gesture events here:
http://help.adobe.com/en_US/as3/dev/WS1ca064e08d7aa93023c59dfc1257b16a3d6-7ffd.html
more on multi-touch/gestures here as well:
http://www.adobe.com/devnet/flash/articles/multitouch_gestures.html
You can create multitouch app , run it on Your mobile and send Touch from device using WIFI .
This is how Im testing this .
But You can also write emulator that will read MouseEvents from stage and dispatch TouchEvents .

Keep App in Focus

I use wscript to launch an application on my machine. I then use this app for 30 seconds before I kill it. I do this using python -
import win32com.client
import time
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("My App")
time.sleep(0.5)
shell.SendKeys('%f')
...
I was wondering if it is possible to ensure that the launched app receives the SendKeys instructions and not another app that I might accidentally give focus to under this 30 second period.
Thanks,
Barry.
Problem
how to guarantee a wsh script SendKeys event goes to a specifically targted application
Workaround
in lieu of a straightforward solution to targeting a specific process with SendKeys you can use the "wait" variant of ShellRun
Example
Change "Before" into "After"
Before
WshShell.Run(run_name)
After
WshShell.Run(run_name,1,true)

Resources