How does Android Things handle long running background tasks? - android-things

How are long running background tasks handled in Android Things? Can developers rely on unbound Services being kept alive by the system?

Because you are the only application running in Android Things you will not be interrupted like usual on an Android mobile device. You can also just use Services like normal if that is what you desire.
Further you can create a background threaded task, this will not be killed or anything and can continue to run in the background for as long as your Activity is around (which with Android Things, will be the whole lifespan of the device being turned on).

Related

TokBox iOS - App Background process singal not working

We are facing some strange issue in the iOS app , we are handling the signal when app in background mode.
It's perfectly working in xcode simulator and the same thing it's not working in real iOS devices. The signals not receiving in app background mode.
Do we need to enable any settings in iOS devices to handle this?
And, It's perfectly working in android devices.
Please help on this.
(Also Project->Capabilities-> Background Modes -> Audio,AirPlay,PIP is enabled for this to work in background.)
Apps sent to the background are generally expected to get suspended unless there is a reason for the process to stay running. In the case of using the OpenTok SDK, usually this means the app will be suspended unless there is a Publisher and/or Subscriber running -- background permission is tied to the AVAudioSession.
If you are trying to just keep a session connected without any subscribers/publishers while the app is in the background, this is not a recommended implementation. Keeping a websocket active for an OpenTok session requires trickling data every few seconds, creating an unnecessary burden on energy and data costs. For this reason, it is recommended to do your offline signaling via APNS rather than through an OpenTok session.
I trust you may have already seen this, but just for completeness, a more in-depth writeup on the topic is available here: https://tokbox.com/developer/sdks/ios/background-state.html
Disclosure: I work for TokBox.

iOS: run app as a service in background

Being relatively new to iOS App development, I wish to develop an app which runs like a service in background (comparable with android service). The goal of my app is to use the native voice recognition, also while the app is inactive. My question is, would it principally be possible to code an app to be able to run also in background? I've read in a few pretty old threads that iOS closes any app after three minutes. However, should it be possible, I would be thankful for any coding example.
I don't think so, because if the app is on background, the local audio recogisation is for Siri.

Can iOS apps communicate via sockets?

I'm going to develop few apps for iOS. Can they communicate to each other via sockets? Let's say one app runs as server (even in background mode) and another as client connects to server app and perform some communication. Does it violate any App Store rules? Any available IPC in iOS if my idea is not working for some reason?
Of course you can and it doesn't violate any rules.
Just just the CoreFoundation libraries.
There's no point in me describing it to you if it already has been all written in the official Apple documentation:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html
You can find here examples, all approaches and things you can and cannot do.
EDIT:
You didn't make that clear but it seems like you wanted the apps to run on the same device. You can do that but that would mean that one app has to run in background, and to do that you need some kind of hack (for example: background updating location mode ON) and that won't get past apple store. You need a very good reason to have your app ran in background (music in background, update location in background for fitness apps etc.)
Besides, it's a duplicate question:
iOS - Is it possible to communicate between apps via localhost?
As long as your apps are in the same app group, then yes, socket IPC is allowed. If not, then no. Sockets map to file descriptors (Berkeley sockets), and these files are sandboxed to the app or app group. More info: http://ddeville.me/2015/02/interprocess-communication-on-ios-with-berkeley-sockets

XCode/iOS Keep connection alive in background

In my app, I open a connection to use the iPad as a tiny FTP Server, then when the app runs, I can access to the app Documents with FileZilla, web browser, etc...
But can I keep this connection opened whe the app enter in background? I tried "Background Modes" but it doesn't work.
Thanks you all :)
EDIT : I use files from this project : https://github.com/sosoyososo/XZCodeBrowser
The background modes in iOS are limited. iOS devices are not designed to operate in the same way as a traditional computer, with multiple long-running tasks. There are various background modes available, as you have investigated, that can help applications perform tasks in the background, but these are more focussed on the user experience (e.g. allowing an app to periodically fetch data or receive location updates) than running "servers".
Apps in the background are managed to reduce demand for memory and maximise battery life, so they can be unloaded at any time.
The VoIP background mode allows iOS to keep listening for network traffic on your app's behalf and re-launch your app in the background if necessary, but if you use this for a non-VoIP app I believe you will have problems with app approval.

How to persist communication after shutting down/turning on the device?

I'm developing an iOS application to keep track of certain system information from the device. The application is supposed to keep sending information even if it is in background. Everything is working fine but when I shut down the device and then turn it on, the application is still in background but it won't communicate the information. Can someone help me to become active my application after turning on the device?
when I shut down the device and then turn it on, the application is still in background
No, it isn't. The app launcher pretends that it is, but in reality it's been shut down. And there's no way you can re-open it programmatically (even less chance for opening a currently dead process from within itself....) - The only reasonable solution I could think of is jailbreaking the device and hooking into SpringBoard so it re-launches all open apps upon reboot, but I don't believe that's a viable option for you.
One way you could achieve this is by the application creating local notifications. These will persist through shutting down the device.
See this fine tutorial: http://www.icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/

Resources