But when I swipe main window application - to close it, service has been closed automatically too.
What am I doing wrong?
The phone is Sony Xperia Z1 Compact.
I want to be able to swipe or close main window and have running service in foreground - like WhatsApp, for example. And Android has nothing to do with it application - so Android it is no main reason about closing service together with app.
I was in the middle of composing a reply when you mentioned that the 1.50 builder fixes it for you, so I will paste it below in case it is needed by anyone else.
----------
You can emulate the behaviour Nikhil describes above for WhatsApp by adding an alarm to your service.
In its simplest form, this would be
var now = new Date().getTime();
app.SetAlarm( "Repeat", 4280, null, now + 3000 );
The above code will just cause the service to restart from the beginning if it shuts down, which is fine for many services but it will forget the content of any variables that it has already set.
If your service is reliant on instructions sent to it at startup by
svc.SetMessage, or on any variables it sets itself, you will need to store any data it relies on each time it is changed.
You will also need to change the SetAlarm call to include a callback and retrieve the data in the callback function.
The data can be stored and retrieved by using
app.WriteFile and app.ReadFile
or any other method you find convenient.
Try your advice.
I test app.SetAlarm() - it working fine. Used DS v1.50a11 with it's Apkbuilder - from that directory.