Service closed when main application swipe

126 views
Skip to first unread message

Кирилл Вертипорох

unread,
Apr 29, 2017, 12:12:33 PM4/29/17
to DroidScript
Create service, example take from here: http://wiki.droidscript.me.uk/doku.php?id=sample_code:file_service

But when I swipe main window application - to close it, service has been closed automatically too.

What am I doing wrong?

nikhil baby

unread,
Apr 29, 2017, 12:35:48 PM4/29/17
to DroidScript
Android OS automatically closes background services for freeing the RAM space!!!!!!

Dave Smart

unread,
Apr 29, 2017, 12:52:23 PM4/29/17
to DroidScript
I think some phones will kill both app and services if you swipe them away.  You should press the back button or use app.Exit to close the app and leave the service running.

What phone do you have?

Кирилл Вертипорох

unread,
Apr 29, 2017, 2:48:51 PM4/29/17
to DroidScript
app.Exit() or back button doesn't give the due effect - the application just go to background and no exit.

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.

Кирилл Вертипорох

unread,
Apr 29, 2017, 3:00:54 PM4/29/17
to DroidScript
When I running application from code in DroidScript and than swipe application's main window (called New Activity), service continues to running. When I close or swipe DroidScript application service also continue to running.

Кирилл Вертипорох

unread,
Apr 29, 2017, 3:03:09 PM4/29/17
to DroidScript
Maybe problem in BuildAPK plugin?

nikhil baby

unread,
Apr 29, 2017, 10:23:53 PM4/29/17
to DroidScript
I think its various with Android OS versions!

In my Jelly bean i have problem like
Кирилл Вертипорох

In my Marshmello, works fine!!!!

Кирилл Вертипорох

unread,
Apr 29, 2017, 11:29:19 PM4/29/17
to DroidScript
But WhatsApp works in all versions without any problems.
So waiting for solve the problem.

nikhil baby

unread,
Apr 30, 2017, 12:43:51 AM4/30/17
to DroidScript
Whatsapp background service is more different from D.S
in whatsApp when the service is closed by the OS it Whatsapp detects it and start it once more!!!!
:)

Кирилл Вертипорох

unread,
Apr 30, 2017, 1:14:05 AM4/30/17
to DroidScript
Anyway, fifth post said about situation, when service continues running after close application - need similar effect not only in DroidScript application, but in apk also.

Кирилл Вертипорох

unread,
Apr 30, 2017, 1:55:09 AM4/30/17
to DroidScript
Build APK from alpha 1.5 Apkbuilder - all start works OK.

Steve Garman

unread,
Apr 30, 2017, 2:07:12 AM4/30/17
to DroidScript
I am glad to hear the problem appears to be fixed for you.

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.

Кирилл Вертипорох

unread,
Apr 30, 2017, 2:18:06 AM4/30/17
to DroidScript
It seemed to fixed the problem - problem still actual.

Try your advice.

Кирилл Вертипорох

unread,
Apr 30, 2017, 2:46:26 AM4/30/17
to DroidScript
app.SetAlarm seems helped. Need some time to make a couple of tests.

Chris

unread,
Apr 30, 2017, 9:54:01 AM4/30/17
to DroidScript
Кирилл Вертипорох, the new beta (1.5) was supposed to include DS restarting a service that was killed my the system.

I would start a thread in the beta and report, maybe Dave can work out the problem.

Chris

unread,
Apr 30, 2017, 10:06:34 AM4/30/17
to DroidScript
...by the system. :-)

Кирилл Вертипорох

unread,
May 1, 2017, 6:02:05 AM5/1/17
to DroidScript
OK, thanks!

I test app.SetAlarm() - it working fine. Used DS v1.50a11 with it's Apkbuilder - from that directory.

Кирилл Вертипорох

unread,
May 1, 2017, 7:43:08 AM5/1/17
to DroidScript
Chris, could you tell me title of the topic, which you create?
Reply all
Reply to author
Forward
0 new messages