android - Calling stopService in onActivityResult() is not effective -


in onactivityresult, wanted stop , restart service. i'm not able stop service code below.

if (requestcode == device_selection) {         if(resultcode == result_ok)         {             intent = new intent(this, myservice.class);             stopservice(i);         } } 

in debugging mode, able reach stopservice() line, app never calls ondestroy() of myservice class (which extends service class) , service not destroyed.

does have idea why case?

my service can started , able destroy service when stopservice() called in ondestroy() method of activity indicates me service class implemented correctly.

you need cache intent have started service use same intent stop service, work

for example lets intent = new intent(this, myservice.class); intent used start service startservice(i) , use same intent stop it. don't create new intent.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -