Android :: Where To Stop / Destroy Threads In Droid Service Class?
Mar 25, 2009
I 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?
View 3 Replies
Jul 2, 2010
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);
} }
View 3 Replies
View Related
Apr 13, 2010
What are the advantages/disadvantages in placing a lengthy network access code in a thread in an activity or a thread in a service? How would it affect the application? I am writing a streaming audio player and from what I've read so far putting the code in a service will still end up blocking the application so a new thread is needed, does anyone know if it makes more sense to put this piece of code in a service.
View 1 Replies
View Related
Jun 12, 2010
I am working on an app that beeps every second. When I hit the home button I want it to close the program and stop beeping. Right now it closes the program but continues to beep.
What am I doing wrong?
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
isdone = true;
mp.release();
counter.cancel();
finish();
}
View 3 Replies
View Related
Jun 24, 2009
I have a service running in the background.I have a background thread that gets a reference to the service from the application's main activity. But when the background thread calls a method in the service to display a toast, I get the "Looper not initialized exception".Why,if I have a valid, bound reference to a Service, does this still happen?
View 4 Replies
View Related
Nov 20, 2010
what I'm trying to do here is implement something like a peer-to-peer client. Being that, it will start a client thread and a server thread.I know Services themselves run in the main GUI thread, so I'll have to start a couple of independent threads (or Asynctasks?) for each server and client. The only thing I'm not so sure about is if I'll better have 1 Service starting 2 threads, or maybe 2 services, each one of them starting their own thread.
View 2 Replies
View Related
Aug 28, 2009
Android experts, I have a tricky question that I would like some advice on. code...
View 8 Replies
View Related
Nov 3, 2010
Im wanting to stop all threads when my main activity closes as some are still running afterwards and are giving NullPointerException as they try to access Array Lists which no longer exist. however none of the obvious methods are working and they are also deprecated. is it possible as im currently using a try/catch statement as a workaround but would prefer a fix.
View 1 Replies
View Related
Feb 10, 2010
When I load my application I also load and Android Service that helps me download files from the internet.The user may have 1 or more downloads at any given time, all in their own Thread which is managed by the service. If the user presses the home button I do not destroy the service but instead let it run, however, if the user presses the back button I do stop() the service as I felt this was the right thing to do (the user would not want stray services running).
This works OK unless there are stray Threads that have not completed yet (this could happen if the internet connection is not active etc.).How could I manage this? How could I stop all Threads as I have no reference to them...or somehow command android to stop my service once all Threads are complete and my app has closed?
View 1 Replies
View Related
Aug 24, 2010
I noticed that in a long threaded email with friends, when it got too long, it was stuck retrieving the email and I had to stop it and then try and download it all again (get remaining) and it never was able to retrieve it. When I finally got home to check the thread they were asking why I wasn't responding. Any tips on how to resolve long email threads not being retrievable?
View 1 Replies
View Related
May 30, 2010
I have a service that regularly queries a web server for new messages. The service stores the new messages in an arrayList. These messages are implemented using a custom class, storing all kinds of metadata (strings and longs).
An activity then connects to this service to retrieve those messages and display them to the user.
I have an .aidl file that describes the interface that the service exposes.
CODE:..........
The Message class extends the Parcelable class which should allow for the IPC transfer.
The problem is this: Eclipse gives me an error saying that the type of List<Message> is unknown. Any imports are marked as invalid.
View 3 Replies
View Related
Sep 18, 2009
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 Related
Aug 2, 2012
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!
View 6 Replies
View Related
Nov 23, 2009
So 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?
View 9 Replies
View Related
May 1, 2010
Everything is in the title.
On the official documentations it is stated that Note that services, like other application objects, run in the main thread of their hosting process and AsyncTask only works if it is executed in the UIThread.
So is it possible to use AsyncTask in a Service class? code...
View 5 Replies
View Related
Sep 1, 2010
What is the class name of media scanner service?
View 2 Replies
View Related
Aug 6, 2010
I have developed an application which is working fine.
In that i have used some static variables and also set Application level variables.
My problem is that even after setting finish() on each activity, application is showing in Running mode.
After closing the application, when i start the application after sometime, it will set the last changes.
How can i destroy my application?
View 4 Replies
View Related
Oct 2, 2009
if the inner UpdateService class is not static, it cannot start the service. The ActivityManager complains "Unable to start service Intent"...
View 8 Replies
View Related
Sep 15, 2010
When I create a instance of the SQLiteOpenHelper, I always need a "Context" to be passed as its constructor's argument. To use this "Context", in my service layer class, I extends Activity class, though I do not display this activity on the screen because it is my service layer. I always get NullPointer exception when I open the SQLiteOpenHelper in my service layer class, Is it because my service layer class extends the Activity class but I did not show this activity on mobile screen? (That's there is no intent to my service layer class), if it is so, how to get rid of it if I wanna open a SQLiteOpenHelper in my service layer class which do not need to extends Activity, but need a Context object to pass to SQLiteOpenHelper?
View 2 Replies
View Related
Jun 18, 2010
In Android, if I want to do some background work, what is the difference between
Creating a Service to do the work, and having the Activity start the Service VS. Creating a standard java class to do the work, and having the Activity create an object of the class and invoke methods, to do the work in separate thread.
View 3 Replies
View Related
Sep 12, 2010
"It's not limited to Android devices, but it seems that increasingly Android more than other platforms is shipping with the worst mobile bloatware. It's a bad trend that's going to lead to consumer backlash and it's destroying the credibility of Google's Android vision."
Entelligence: Will carriers destroy the Android vision? - Engadget
View 5 Replies
View Related
May 8, 2009
I'm posting this to share the lessons I learned while working with IntentService. IntentService has a single constructor that takes a string argument "name". The documentation has no description of what name is used for. In looking at the sources, I found that its only use is in naming the worker thread for the IntentService. This thread is named IntentService [name].
I initially implemented the constructor of the derived class to also take a String argument and passed it along to the derived class. This is wrong. This will cause the startService() call to generated a java.lang.InstantiationException in the application containing the service i.e. you don't get the exception in the application calling startService(). A clue to the actual problem is a little further up in the logs:"newInstance failed: no <init>()"
The derived class must have a Default constructor and that constructor must call super() passing a string for the name component of the worker thread name.
public class MyIntentService extends IntentService {
public MyIntentService() { super("MyIntentService");
} @Override
protected void onHandleIntent(Intent intent) {
// Handle events on worker thread here }
View 2 Replies
View Related
Jun 22, 2010
Hi, custom classes which are part of a framework, so nothing graphical. One of those (singleton) classes is a Logging class which send logs to my server. I noticed that even though I can call the classes methods in my service it actually won't be logging anything... In my specific example it's osmething like : Logger.getInstance().log("Whatever I want to Log"); Obviously the getInstance is a static method so it can be accessed from anywhere within my project right away.. I was wondering though why this method for example isn't getting called ? Also how do I debug a Service ? Btw I am using of IPC from one of my Activities which gets bound to the service and can start/stop the music for example...
View 9 Replies
View Related
Jun 1, 2010
I was wondering if it's possible to call specific methods defined within the AsynTask class from another class and/or service ?
In my specific case I have a Service playing some sounds, but the sound is selected from a List with available sounds...
When a sounds is selected it is downloaded from my home server, this takes some time (not much, let's say around the 3-4 seconds, the sounds/effects aren't big in size)...
So my problem at the moment is that I have a service to play those sounds, and when I select one I wanted to show a progressdialog... The way (if I understood correctly) is to use an AsyncTask, but the only thing the AsyncTask will do is telling my Service to play a specific sound from my server... So there is no "callback" from the service to the Asynctask...
How can I call a running AsyncTask, which sits in another class, and tell him all work is done and thus he can stop showing the ProgressDialog ? Or am I over-engineering it and there are other ways ?
View 2 Replies
View Related
May 19, 2010
The problem seems to be that the Service class does not inherit the > findViewById() method.
View 3 Replies
View Related
Oct 12, 2011
am trying to call a class from the main and am getting an error and the program is stop working. am trying to call from the main.class the test.class
on the main i have write the following code
Intent connectIntent2 = new Intent(Conn.this, Test.class);
startActivity(connectIntent2);
and on the test.java i have write[code]....
the R.id.button_scan is been define in the main.xml and i just want to make it invisible.
View 1 Replies
View Related
Jun 6, 2011
I am trying to create a drools app on android using eclipse. It compiles /builds correctly in Eclipse. But when I run it in emulator or android device, it says
W/System.err( 322): java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService '
I have the required jars added to "libs" directory of the project and the jars are also added to the build path in eclipse.
View 2 Replies
View Related
Apr 30, 2010
I am trying to execute a {public void} method in Service, from scheduled TimerTask which is periodically executing.This TimerTask periodically checks a condition. If it's true, it calls method via {className}.{methodName};However, as Java requires, the method needs to be {pubic static} method, if I want to use {className} with {.dot}.The problem is this method is for notification using Toast(Android pop-up notification) and Status Bar.But for this to work, the method must not have {static} modifier and resides in Service class.So, basically, I want background Service to evaluate condition from scheduled TimerTask, and execute a method in Service class.Can anyone help me what's the right way to use Service, invoking a method when certain condition is satisfied while looping evaluation?
View 1 Replies
View Related
May 23, 2010
I've noticed that changing the background color of an android widget (f.ex. Button or TextView) by program:
myButton.setBackgroundColor(Color.BLUE);
makes it to loose its 3D shape, border, and shadows effects, and then appears like a ugly flat square. What am I missing?
Sorry for the very naive question but I couldn't get it right although tried for a time.
View 2 Replies
View Related
Dec 11, 2009
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?
View 3 Replies
View Related