Android :: Make Service Stop Itself?
Dec 11, 2009I start a service in an activity then I want the service to stop itself after awhile.
I called stopSelf() in the service but it doesn't work.
how to make the service stop itself?

I start a service in an activity then I want the service to stop itself after awhile.
I called stopSelf() in the service but it doesn't work.
how to make the service stop itself?
Okay when user presses log out button what's supposed to happen is:
Code:
stopService(myIntent);
unbindService(mConnection);
mIsBound = false;
I need to shut down the service on background.Except the service restarts itself over and over again! Even if I kill the program from task manager the service restarts itself. Other programs aren't using the service. when I uninstalled the program the foreground program information popped up indicating it was STILL there(albeit this I solved by rebooting phone).
When user says he's finished with the program 'least he can expect is for the program to stay down rather than keep eating battery by acquiring GPS signal and sending them to server. The program is not intended to be "once you log in you need to Uninstall me and reboot phone to get rid of me!" type of program!
I have a service receiving and sending data to a server in separate threads each. The service lifecycle methods look like this:..................
View 3 Replies View RelatedIs there any way to correctly stop the camera service? This does not seem to work: After doing that the camera does not work, even if I use the program that is pre installed in my handset.
View 2 Replies View RelatedI am programming a game. I have a service for the background-music. When I press the home-button and leave my activities, the service still runs in background. How can I stop the service, when there is no more visible activity in my program and restart it, when the user goes back to my game (some activity of it)?
View 8 Replies View RelatedI have a service, that requests another class, which launches an AsyncTask
Service->Weather Class->Execute Method->Asynctask->Execute
this is launched in the service by
new Weather(this).execute(); // the execute is a method of the class, not of the AsyncTask
how do I detect in Service that the AsyncTask finished so I can call stopSelf?
Is there a way I can test if there are any other activities in my app still alive? I am looking to stop a service in an onDestroy method, but only want to do this if there are no other activities from my app still alive on the stack.
I have the call stop the service in the main activity's onDestroy() method. This works perfect EXCEPT that if a user launches my app, then launches a few activities in my app, then hits the home screen and RELAUNCHES my app, they will subvert my order and the main activity will now be above other activities of my app. From this state, if they hit the back button and 'back out' of my home screen they will trigger the onDestroy() method and kill the service even though there are other activities open on the stack. I want to avoid this by stopping the service ONLY if I am sure there are no other activities of mine open on the stack.
I have a location manager: mLocationManager01 = (LocationManager)getSystemService (Context.LOCATION_SERVICE); because i want to stop the gps service, but when i use mLocationManager01.removeUpdates(mLocationListener01); that's not working to stop gps. how can i stop it?
View 4 Replies View RelatedIs there an API, or a registry I can do in the manifest to make sure my service is being run at the device start up and being shut down before the device shuts off?
View 3 Replies View RelatedI created and binded a service in an activity and I would like to know how I can avoiding the android application to stop when I press the back button. When the back button is pressed the onDestroy method is called and I unbinded the service in this method. I try to prevent it by taking care of the back button event and manually call for onStop() method but it always called onDestroy after, why?
View 1 Replies View RelatedI have a service which runs in the background when the user starts using my app. I am using it to do some posts to our server. I always close my service by calling stopSelf as soon as the posts have been made or failed.
But I recently observed two times that my service did not stop. I saw that in the running services in settings on my device that it has been sitting there for over a few hours.
So I was trying to see if I can alternatively set a timer using which I can force the service to stop after a few minutes no matter what.
I am trying to call my service class's stopService() method from my activity. But I don't know how to access stopservice method from my activity class. I have the below code but its not working. This is HomeScreen class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
enablecheck = (CheckBox)findViewById(R.id.enablecheck);
enablecheck.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(enablecheck.isChecked()){
startService(new Intent(HomeScreen.this, AutoService.class));
} else {
stopService(new Intent(HomeScreen.this, AutoService.class));
} } });
}
This is Service Class:
public class AutoService extends Service {
private static final String TAG = "AutoService";
private Timer timer;
private TimerTask task;
@Override
public IBinder onBind(Intent intent) {
return null;
} @Override
public void onCreate() {
Toast.makeText(this, "Auto Service Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
int delay = 5000; // delay for 5 sec.
int period = 5000; // repeat every sec.
timer = new Timer();
timer.scheduleAtFixedRate(task = new TimerTask(){
public void run() {
System.out.println("done");
} }, delay, period);
}
@Override
public boolean stopService(Intent name) {
// TODO Auto-generated method stub
timer.cancel();
task.cancel();
return super.stopService(name);
} }
I had the program I wrote a service, and in service has written a timer, change the timer for one minute cycle time, but why the program in the phone standby (screen lock) were time, I have the timer will be stop running, when I click the menu, get back to normal mode when the timer will automatically have to run? What is the reason, how to solve?
View 2 Replies View RelatedI have created a threaded service the following way. code...
After I close the application the phone works really slow and I guess it is due to thread termination failure.
Does anyone know what is the best way to terminate all threads before terminating the application?
I start service by using:
private ServiceConnection _serviceConnection = new ServiceConnection() {...}
bindService(new Intent(this, MainService.class), _serviceConnection, Context.BIND_AUTO_CREATE);
I want to 'restart' the service. (Let's not argue why I want to do that)
I do that by:
unbindService(_serviceConnection);
// Do some initialization on service
bindService(new Intent(this, MainService.class), _serviceConnection, Context.BIND_AUTO_CREATE);
I noticed service doesn't die(onDestroy doesn't run) until I call next bindService();
So some static initialization I did on service got cleared by onDestroy() implementation.
Question: How do you make sure unbindService() will stop service (run onDestory()),
so that I could do initialization after and re-run bindService()?
I saw this in the "running services".. and i stopped it, what the hell is it and should i not have stopped it?
View 2 Replies View RelatedHow can I make the ListView immediately stop scrolling on a finger down event? It keeps scrolling if I give it a big swipe and doesn't stop immediately if my finger is pressed down again. Any idea?
View 3 Replies View RelatedHow do some android app make their service restart even if killed from task manager? A good example is Lookout security app. What I guess is that it has registered for all common events that are announced like app installed unistalled, interenet available ,etc.Is this a way to keep your service running ?Another solution I found was to make 2 services monitoring each other, so if one gets killed restart another.Which one would be a proper approach? Is there any way in android to start booting automatically(if device is switched off) once connected to power source? I have never heard this on mobile platform.This is possible for PC through bios feature. Can it be done on android?
View 1 Replies View RelatedI'm trying to create a service that can run in backgroud. To start this service i'm using a activity to invoke startservice() API. This will start the service but when i exit the activity by invoking finish() and system.exit(), I see that service created/started by the activity is also terminated.How can i make sure service runs indefinitely even after terminating activity that started the service?
View 2 Replies View RelatedI have an Android application with a background running Service. When the Service crashes or gets killed by Android I can see that Android tries to restart it again. However the Service never actually restarts, I can see Android scheduling the restart but it new actually happens.
My code is as follows:.................
How do I make my service always alive?? If my service gets killed because of an exception or if the VM kills my service on low memory, How do I make sure that my service is always running?
View 14 Replies View RelatedSo I have everything set up to automatically use my Google Voice number now, and started getting SMS texts in both my messaging inbox and in GV. I figured out I needed to turn off the SMS forwarding in GV, but it turns out I like using the default messaging app more than the one in GV.
Is there a way to make the GV app stop checking for SMS messages but still download my voicemail? I don't want to make it stop checking all together but I'd like to use the other app for SMS's.
I'm making a game, but the game lags a bit every time onCellLocationChanged or updateNetworkNameExtension shows up in my Log file. What is making these two run? Is there a way to make them not run?
View 3 Replies View RelatedI picked up the Sprint HTC Evo. This is my first android phone and it's a big upgrade from the windows based HTC Touch Pro that I used to put up with. However, every single notification makes a massive, loud, Beep And I can't figure out how to turn the volume down on it, except to put the phone in vibrate mode. Windows had two volumes: one for system, and one for the ringer. That made a lot of sense.
I think my co-workers are going to get really angry with me if I don't figure this out soon. At first, it was just text messages, but now it's facebook and everything else. Can someone please tell me how to shut up this dumb robot?
I'm not sure what info I need to give you about this, but it's the launch version of the Evo, I did not change anything related to this problem - still using the default applications and such.
my application objective is to save location updates every ,let say, 20 minuets .I used service and it worked fine , but when i lock the screen or it is locked automatically the service stop running .when i unlock it , service runs again.How to make my code run all the time in all conditions?
View 1 Replies View RelatedSo sometimes I'll go into my contacts and notice that some of them have the green ball lit up telling me that they are online in gtalk. Now I am not signed onto gtalk... but yet somehow I see that in my running services that GTalkService is running.
I can only assume that its eating away battery trying to see how is online and not. I certainly don't need this info unless I wish to go online myself... in which case I would actually go into the gtalk app.
ANyways, obviously i've been killing it in the running services, but it just comes back all on its own. ANy idea why or how to stop it?
Updated my phone to 1.47 or whatever it is. Now my phone won't stop vibrating when I get a notification. Volume is up. Vibrate for everything is off. Haptic feedback is off...Rebooted twice...
View 13 Replies View RelatedSO I am trying to email a few photos to my home address, it has taken a half hour and has dropped my battery 43% in that 30 mins...any way to stop the email? Its also blocking all in coming mail to the phone
EDIT This is soo frustrating, it just sits attempting to load conversations in my inbox and eats my battery
Is there an app to download to make the Motorola Droid stop ringing when touching the screen? I can't figure out a way to turn off the sms ringer other than just letting it play out.
View 4 Replies View RelatedI have developed an android service. Any android app can use it's API's to get some kind of news updates from this service. I want to distribute this service so that any android app on the phone can use this service. My questions here are :When some android application try to use its API on the phone and suppose that service is not available on the phone then what will happen ?How will android application developer will make sure that the service is available on the phone?Does application developer has to bundle service with his application ? If yes then wont be there multiple instances of same service on phone if multiple application contains same service on the phone?
View 1 Replies View Related