Android :: Application Threads Vs Service Threads
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
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
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
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
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
View Related
Sep 22, 2010
Are there any limits on the number of threads or any constraints on how the emulator (under Eclipse) schedules the application threads? I get suspended threads that don't really wait on anything but rather get bumped out from execution time. I will try using the Debug class to get some statistics on the thread alloc etc. even though the DDMS does that already. One example is, I have a simple class that simply prints a '.' every 3 seconds - well, the LogCat shows the emulator collecting garbage objects but the thread is suspended and does not print the '.'
View 7 Replies
View Related
Dec 20, 2009
What is the maximum number of threads allowed per application?
View 2 Replies
View Related
May 21, 2009
My application starts a remote service and binds to it. If I close the application with the "back" button there are still some threads running (listed in the Debug View of Eclipse) - main thread, and three Binder threads. In onDestroy() I call unbindService(service_connection) - is there something else to clean up?
View 4 Replies
View Related
Feb 18, 2009
the thread sleeped not killed and it wakes up after 10 sec and try to post message and it causes exception. is there any way to kill the threads those are in sleep mode while exiting the application?
View 5 Replies
View Related
Nov 11, 2010
Recently dived into the Android world, buying myself a HTC desire about 2 weeks ago.
So far, I love the setup, features and feel, the only thing I'm a little worried about is a little bit of lag.
I know the phone is renown for its processor speed and RAM, but scrolling through things like my SMS threads, the application list, and Friend Stream it is a bit 'jittery' and a little laggy. Every now and then an application like Facebook or the SMS application will crash on me. And I know I'm a rather fast texter, but when I'm texting sometimes the phone cannot quite keep up with what I'm writing.
I have no unusual applications installed and do not use task killers.
Is this normal? Or might there be some reason why its functioning a little slower than it should.
View 8 Replies
View Related
Oct 22, 2010
We are in the process of refitting some of our recievers and services with IntentServices (mostly to address rare ANR issues - and because IntentService is pretty cool...). In one case we are converting a traditional service to an IntentService. The original service fired off a few methods whose job was to download data from our servers. Each of these requests would spawn a thread of their own to do the work (apparently not fast enough to avoid the occasional ANR). So now we have a question concerning the life cycle of these processes.
For example, the following situation demonstrates what is happening:
- Start Intent Service - Trigger Download1 - Download 1 thread starts - End Intent Service
- Download 1 thread continues..... - Download 1 thread ends
Our question concerns our exposure to the OS shutting down the Download 1 thread because the Intent Service has terminated before it finishes up. Not sure if it is becomes more or less likely that the OS will view it as something that can be flushed.
If the Download 1 thread is more likely to be flushed by OS we will need to take a different approach.
View 4 Replies
View Related
Apr 6, 2010
I am working on a simple application (studying purposes) which list all the files from a selected folder. On top of that I would like to have a search feature where the user can search for files (the code for that is already in place). Now, I was thinking about having the search running in the background somehow, whilst the user can still navigate, create folders, copy, sort and do other stuffs normally. When the search finishes the user would get a notification and then could click on it and go to that activity (It ideally should be the same ListView I already use for browsing the files, I would just need to update the Adapter there with the latest processed data after clicking in the notification). What's the best answer for that? Threading or AsyncTask?
View 4 Replies
View Related
Feb 22, 2010
I'm trying to understand the idea behind the Services. If it runs in the program's thread, why not create just a separate thread (or AsyncTask) to do the job? Can a service keep running in the background? For example, i want to create a task that will continuously be polling data from a server, even if the main application is not running. Can this be achieved with a Service?
View 8 Replies
View Related
Mar 13, 2010
while debugging and app that uses AsyncTask to record audio and update UI I noticed that everytime that an AsyncTask object ends running (finishes doInBackground and onPostExecute or on Cancelled it´s thread stays alive (running status).At least for me that should not be the behavior of the class since the doInBackground task may not stay running forever (as an example the android manual says that a status bar should be updated by an asynctask, and it won´t last for the whole app running time).Is there anything I´m missing, as a method to destroy it, or should I just ignore and keep creating threads as I need and the VM will handle them as it needs resources?
View 9 Replies
View Related
Jun 5, 2010
how do i save certain threads?
View 1 Replies
View Related
Aug 3, 2010
As my app matures, I find myself finding more and more uses for threads. By now I must have about 25 threads, all doing important things and working together in symphony.
I notice however that my app is sitting around 15.5MB resident. Compared to the browser (+/-35MB) I feel pretty safe, but I do notice the resident size of my app ever increasing.
The question is, how much overhead is involved with adding a thread?
I'm also wondering if the synchronized keyword encounters more and more latency with each new thread that is present?
View 4 Replies
View Related
Mar 4, 2010
I have an activity that uses a Timer (java.util.Timer) to control the display. I set it off to repeat its run() method every second or so. When it runs, it updates some View elements.
As Timer runs in its own thread, I assumed this would be reliable. But I notice that sometimes there is a stutter, or delay, in the views updating. It's like they occasionally get stacked up, and all happen together. Studying the output from logcat, I notice that this happens when the device is doing something else - some system functions, or sometimes a garbage collection.
How can I avoid this? I'm not aware I can run the main activity in a thread of its own, can I? If the timer has its own thread, why is it affected?
View 8 Replies
View Related
Nov 17, 2009
We are developing an application that needs to suspend and resume threads like a debugger (meaning in a non-safe way like Object.wait() and Object.notify()).In the Java SDK the methods Thread.suspend() and Thread.resume() are deprecated but we can still use them. Also there is the Java debugger API which allows one to do that if you connect to the VM as a debugger. Is there some API for android we can use? Is there a published Java Debugger API we can apply for Android?
View 2 Replies
View Related
Oct 30, 2009
I have a question about the background thread handling change that went into SDK 1.6. I read here that BG threads get placed in a scheduling class that can't use more than 5-10% of the CPU in order to keep the foreground responsive. Do system services get into that scheduling class?
My app uses repeating alarms. It was great with 1.5, very reliable. Since the upgrade to 1.6, the phone seems to be dropping some of my repeating broadcasts, especially if I am doing something fun in the foreground like with WIFI when the Alarm is supposed to fire. I do not have any of the task killer programs that have been a hot topic lately. To be clear, the dropped alarm broadcast behavior is intermittent. I am not 100% sure if I really am doing something when it has failed. If the timer is a one shot, it seems to work better but there is no real empirical evidence here. My phone is usually in my pocket when I fire one of the one shot alarms. If my theory about system services in the background scheduling class is correct, then I probably cannot find a workaround or defensively code a solution. Will it be the same in 2.0?
Have others seen issues with alarms and with the setRepeating method? I am looking for suggestions to troubleshoot this problem. How can I determine if the problem is the broadcast, if it is the repeating alarm creation, or if there is some other issue like low memory coming in to play.
View 13 Replies
View Related
Mar 4, 2010
I have a couple of worker threads in my app which I stop and restart during onPause() and onResume(). I use a method that clears all the reference to and from the threads when stopping. However ThreadGroup is still retaining a reference to my threads and causing a small memory leak. After pausing and resuming my app about 40 to 50 times I will then get OutOfMemory Errors when loading bitmaps. Allthough this doesn't effect most of my users I do get occasional reports of crashes. How can I remove the references to my threads from ThreadGroup so that GC can do it's job.
View 4 Replies
View Related
Jan 9, 2010
Currently I have two threads, other than the UI thread, which need to communicate with each other. Thread one needs to be able to send messages directly to thread two, and vice versa. What is the best way to implement this?
At the minute, my code looks like this...
View 4 Replies
View Related
Sep 24, 2010
When i try to delete a threads, handcent crashes. the reason i want to delete threads is because i believe my conversations of upwards 2000 messages are slowing down the handcent performance and therefore my phone >
anyone else have this problem or know a way to delete all that garbage?
View 2 Replies
View Related
May 17, 2010
I'm writing a live wallpaper, and I'm forking off two separate threads in my main wallpaper service. One updates, and the other draws. I was under the impression that once you call thread.start(), it took care of everything for you, but after some trial and error, it seems that if I want my update and draw threads to keep running, I have to manually keep calling their run() methods? In other words, instead of calling start() on both threads and forgetting, I have to manually set up a delayed handler event that calls thread.run() on both the update and draw threads every 16 milliseconds. Is this the correct way of having a long running thread?
Also, to kill threads, I'm just setting them to be daemons, then nulling them out. Is this method ok? Most examples I see use some sort of join() / interrupt() in a while loop. I don't understand that one...
View 1 Replies
View Related
Jun 24, 2010
I have two questions about sensor listeners
1. from which thread are sensor values updated and should this be synchronized? can sensor's listener callback be a good place to call custom's view onDraw method? as this should be done from different thread. I cant find anything about it. In another words my problem is that I want to listen to sensors change and draw something on view surface but I dont know which thread (the main thread of the application?) is updating sensor's state
2. If I register sensor listener with SENSOR_DELAY_FASTEST my application is not responsive at all! Raw application with TextView only is not reacting to go back or home button! How should I deal with this or am I doing something wrong?
View 4 Replies
View Related
Sep 13, 2010
Trying to understand the Android framework model. I have an application that needs to have several threads running. On thread gets GPS fixes, another picks up GPS fixes and pushes them to server, and yet another occasionally polls a server for dispatched orders. Some of these threads update status Views as well.
Since I am new to Android, the application framework model hasn't clicked for me. Where are these threads started? Right now I start the threads in the initial Activity, but if I understand it right, once that Activity goes invisible it is stopped. Furthermore, I have to track GPS and network statistics so that I can have a View which may (or may not) be the active View.
View 1 Replies
View Related
Aug 30, 2009
In the following sequence of events:
1. Start a new thread (as a result of a button click - or similar).
2. User changes the screen orientation (causing the Activity that started the thread to be destroyed).
3. Thread finishes, and wants to do some dialog (or any UI) work. However, doing a showDialog, dismissDialog, ... will crash, as the thread it still referring to the old Activity.
This can be solved by updating the data in the thread to refer to the new Activity upon a screen orientation change.
However, couldn't the Android framework just forward any requests from a destroyed activity, to the newly created Activity, saving us developers of handling it ourselves?
View 24 Replies
View Related
Mar 18, 2009
I was wondering, why there is no functionality to pin threads a user is interested in. As there is such a high traffic on these groups, it takes time to find the threads I answered to or some I am interested to see how the problem is solved. Sometimes you don't remember the naming of the subject or the user that wrote it and then searching becomes annoying. An easy way would be to pin some threads! I mean the right side is nearly empty an everybody is authenticated when she uses the group, not to just read.
View 7 Replies
View Related
Aug 25, 2009
I would like to know how to run a listener on an isolated thread. Because I would like to use a LocationListener and make some calculations in the main thread. So the LocationListener would be "slow down", because of those calculations. Is it possible to have it run in a different thread? Or is it by default in a separate thread?
View 2 Replies
View Related
Sep 7, 2010
I want to create one method and call the created Thread inside that method in my Android Application, I am new to Java as I had told before. Can anybody giive me an example of how should I create a method and call a Thread inside that method!
View 2 Replies
View Related