I read the thread on background tasks but I am still confused.
I have a program activated by a phone shake. That works when the app is active. The moment the phone goes to sleep the shake does not wake it up.
Step counter programs work for weeks in the background, how?
The phone flashlight comes on with shake even when the phone is asleep, no login needed
The camera wakes up with a wiggle and if the phone is logged in it starts the camera but it the phone is asleep it wakes up and prompts you to login to continue.
So all kind of different ways to keep apps engaged, how to do it?
Do you mean the iToo topic ? There are many examples provided there for how to run apps in the background. Did you try any of them ? What is it you do not understand ?
you could adjust the following example to your needs
Taifun
thanks i will check it out.
i looked at the blocks - that looks pretty straight forward. i assume instead of shake i can use the GPS location change event or a time event too.
will try
thanks again
erhard
no i have not seen this one and i will check it out, but what made me give up was one comment stating that android is inherently not designed to run background tasks for long time and it is not well defined what 'long' time means.
for example i know my itunes radio streaming can run for days sometimes and sometimes for only a few hours - so pretty unreliable and that seems to support the above statement.
thanks for the lead
erhard
To get location change events in the background you need background location permission
My paid locationservice extension is able to do it App Inventor Extensions: Location Service | Pura Vida Apps
What exactly do you mean by a time event? Usually you would use the alarmmanager functionality of the Android device to keep the battery usage as low as possible to trigger a background activity at a given time... my paid alarmmmanager extension could help with this... App Inventor Extensions: Alarm Manager | Pura Vida Apps
Please understand the difference between the 2 different types of service which can run in the background... see the itoo thread. Usually you would use a Foreground service.
Types of Service
A service is basically something that runs also while the app is not open or when the app is closed.
- Background Service: A non-visible background work that can be scheduled using Itoo.
- Runs silently without user noticing it.
- Vulnerable to being stopped by the system abruptly, can only run upto a few minutes in modern devices depending on the phone brand, OEM, OS installed, etc. (also see dontkillmyapp.com )
- Foreground Service: A user visible and recommended way to execute something in the background.
- Itoo is primarily based on supporting this service.
- Generally can work non stop for ever, but could be limited to a few days or less time depending on the phone brand you use.
- A permanent notification is shown while this service is active starting from Android 8 (Oreo).
Taifun
Thanks, hm a lot to digest. In my case I wrote an app that can send out a pre-recorded SMS and automatically attach the current gps coordinates at Time of sending.
However Before sending the user is still prompt to confirm in order to avoid false alerts etc.
So while the phone is asleep in the pocket it still should update the current location and also register a shake event. Not sure if this is no foreground or background.
This would be possible using the forementioned locationservice extension
If I understand correctly, after shaking you like to open your app immediately even if the device is locked to then send a sms with the latest location? The latest version of the alarmmanager extension would be able to open the app also above the lockscreen, see also here
To detect the shaking see the already provided example here Run app in background, that fires an alarm whenever phone is shaking - #4 by Taifun
Taifun