Re: [android-developers] Cant stop service
Thanks very much for the help, that did it. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Cant stop service
Hi I have a toggle button which i use to start and stop a service When i press the button the service starts fine but i cant seem to stop it. The boolean a in my code below return true but the service keeps running. What am i doing wrong? any help would be great. Thanks in advance toggle = (ToggleButton) findViewById(R.id.toggle); toggle.setOnClickListener(new OnClickListener() { public void onClick(View v) { boolean checked = toggle.isChecked(); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean(toggle, checked); editor.commit(); Intent toggleIntent = new Intent(MyActivity.this, MyService.class); if (checked) { try {ComponentName a = startService(toggleIntent); Log.w(TAG,toggle Enabled: +a.toString());} catch (Exception e) {Log.i(TAG,Cannot Start toggleService: +e.getMessage()); Toast.makeText(getApplicationContext(), Cannot Start toggleService:\n + e.getMessage(), Toast.LENGTH_LONG).show(); } } else { try{boolean a = stopService(toggleMapIntent); Log.w(TAG,toggle Disabled: +a);} catch (Exception e) {Log.i(TAG,Cannot Stop toggleService: +e.getMessage()); Toast.makeText(getApplicationContext(), Cannot Stop toggleService:\n + e.getMessage(), Toast.LENGTH_LONG).show();} } } }); -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
Do you have any code that binds to this service? 2011/6/20 Boozel boozelcl...@gmail.com Hi I have a toggle button which i use to start and stop a service When i press the button the service starts fine but i cant seem to stop it. The boolean a in my code below return true but the service keeps running. What am i doing wrong? any help would be great. Thanks in advance toggle = (ToggleButton) findViewById(R.id.toggle); toggle.setOnClickListener(new OnClickListener() { public void onClick(View v) { boolean checked = toggle.isChecked(); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean(toggle, checked); editor.commit(); Intent toggleIntent = new Intent(MyActivity.this, MyService.class); if (checked) { try {ComponentName a = startService(toggleIntent); Log.w(TAG,toggle Enabled: +a.toString());} catch (Exception e) {Log.i(TAG,Cannot Start toggleService: +e.getMessage()); Toast.makeText(getApplicationContext(), Cannot Start toggleService:\n + e.getMessage(), Toast.LENGTH_LONG).show(); } } else { try{boolean a = stopService(toggleMapIntent); Log.w(TAG,toggle Disabled: +a);} catch (Exception e) {Log.i(TAG,Cannot Stop toggleService: +e.getMessage()); Toast.makeText(getApplicationContext(), Cannot Stop toggleService:\n + e.getMessage(), Toast.LENGTH_LONG).show();} } } }); -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
No, i need the service to run independently from the activity -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
Ok. Your code calls startService and stopService with different Intent objects: toggleIntent vs. toggleMapIntent. Does the stop intent actually point to the service you want to stop? If not, you are stopping someone else's service. -- Kostya 2011/6/20 Boozel boozelcl...@gmail.com No, i need the service to run independently from the activity -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
sorry i changed the variable names to make it more readable they are actually both the same intent toggleIntent declared above. Could it be because the intent would essentially be redeclared each time the button is pressed with the line Intent toggleIntent = new Intent(MyActivity.this, MyService.class); ? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
Changing that doesnt seem to help? Any ideas? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
How are you checking for whether the service gets stopped? 2011/6/20 Boozel boozelcl...@gmail.com Changing that doesnt seem to help? Any ideas? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
The service continues to write to the log -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
Does the service's onDestroy ever get called? 2011/6/21 Boozel boozelcl...@gmail.com The service continues to write to the log -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Cant stop service
You are responsible for stopping whatever work your service does in its onDestroy(). You can look at the current state of all actively running services with adb shell dumpsys activity services. Make sure your service is actually in there. If it isn't, you aren't cleaning up your worker. On Mon, Jun 20, 2011 at 1:34 PM, Boozel boozelcl...@gmail.com wrote: The service continues to write to the log -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en