android - Service not closed properly -


i have android application starts service in main activity command:

bindservice(new intent(ctx, myservice.class), _connection, context.bind_auto_create); 

the main activty excatly nothing service (thats why didn´t provide code service connection). idea main activity handels service lifetime!

it "stops" service code after user clicks "close" button of app:

if (_service != null) {     unbindservice(_connection); } //some cleanup here ... system.exit(0); 

i know @ point no other activity binded service cause every activity called main activity , unbind service @ "onstop".

so problem service wont call "ondestroy" when user closes app! when remove "system.exit(0)" line close normally!

how can make sure service closed in situation?

edit:

ok read discussion: is quitting application frowned upon?.

now rebuild activities. have 1 activity calls service startservice, after binds service. when activity destroyed calls unbindservice.

the service returns start_sticky in onstartcommand make harder kill it. calls stopself when work done.

now have problem serviceconnectionleaked message if binding still exists! whats that? how prevent this?

use finish() instead of system.exit(0)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -