Android :: Service Thread Priority
Dec 16, 2009
I have two apps that use a service to upload and download files and data. I've noticed that when the service gets very busy, it can cause the UI to block, up to the point that Android shows a "force quit/ wait" popup. In order to avoid that, I run tasks in a service at a lower priority. This way, the service will never cause the UI to hickup. Also, the service stops if the app hasn't been used for a certain number of minutes. I don't want to keep resources if the user isn't using my app.I have found that some of my users run apps that run services permanently at normal priority. Such a service starts at phone switch on, and keeps running indefinitely, downloading vast amounts of data. My policy of being nice to other apps doesn't pay off: these agressive third party services push my service away so it never gets anything done. As one of my users told me, my app has hickups, until he kills the service of this app X, after which my app runs smoothly, snappy, and fast.
My question is, should I be nice to other apps and to the UI in my own app, or should I just run a service and agressively take all resources I need - or don't need? This is one issue where Android is different from iPhone. We can run services, but by doing so, we can cause damage to other peoples apps. Of course, my "question" doesn't require an answer. I'm just curious after what other people think, what your experience here is.
View 5 Replies
Feb 9, 2010
I am programming a game with fast graphics. The MediaPlayer is stuttering sometimes. When I have the MediaPlayer in a service, it does not stutter, but some people here adviced me not to use services if they should stop automatically when the user ends my application. So how can I set the thread-priority of the MediaPlayer-Object? SoundPool uses the MediaPlayer and with SoundPool, you can set the thread-priority, but I cannot add my audio-file to SoundPool, because its size is about 2mb (too big for SoundPool). I can lower my main-thread-priority so that the MediaPlayer has a relatively higher priority, but isn't this a bad idea?
View 2 Replies
View Related
May 10, 2010
I have a multithreaded streaming app which has mainly the following 5 threads. 1 Main App(UI) Thread 1 controller thread (in native) 1 audio decoder thread (in native) 1 video decoder thread(in native) 1 thread to query the head position of audio (in Java) Apart from this I have video rendering with OpenGL. My problem is, if I query the thread priority using the Thread.getPriority method (my native threads make callbacks to Java and I am making the query at that point of time), I am getting the priority of each of them as 5. For my audio query thread (the last one in the list) I am explicitly setting the priority using Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO); Also for my decoder threads, I am giving higher priority than my controller thread(using pthread APIs in native). But still finally all of them seem to have same priority. Also what should I be doing to increase the priority of my threads(both from Java and native)?
View 6 Replies
View Related
Apr 26, 2012
I read somewhere that iPhone UI is so smooth because the thread which renders the UI has the REALTIME priority... so is that possible to mod android's UI thread priority?
View 2 Replies
View Related
Aug 13, 2010
Is there a standard way in Android to create an unkillable service with very high priority, assuming you have complete access to the device (as in you're building your own device on something like a beagleboard, not just installing an app)? I'm playing around with sip phone stuff, and it seems like just doing it as an app isn't going to work if you want high voice quality. (Assuming you want to be able to let the user switch away from the actual sip app and use different apps; all the sip phones I've tried have failed to maintain decent audio if you're multitasking.) Or would you just run the phonecall software outside Android in a normal Linux process and communicate with Android apps over sockets?
View 2 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
Jan 18, 2010
I am new to Java and Android.I would like to retrieve remote data and display it within my activity. To prevent tying up to UI, I understand that I can do this in another thread. (I thought I could just-as-well fetch this remote data from within a service, but that appears to tie up the UI thread also). So now I'm beginning to think I need to either run the logic from a new thread within a service, or run a service within a new thread. But which? I have found many examples online of running new threads or services, but I have yet to find an example of both at the same time.
View 7 Replies
View Related
Jun 12, 2010
In Virgil Dobjanschi's talk, "Developing Android REST client applications" (link here), he said a few things that took me by surprise. Including:
Don't run http queries in threads spawned by your activities. Instead, communicate with a service to do them, and store the information in a ContentProvider.
Use a ContentObserver to be notified of changes.
Always perform long running tasks in a Service, never in your Activity.
Stop your Service when you're done with it.
I understand that he was talking about a REST API, but I'm trying to make it fit with some other ideas I've had for apps. One of APIs I've been using uses long-polling for their chat interface. There is a loop http queries, most of which will time out. This means that, as long as the app hasn't been killed by the OS, or the user hasn't specifically turned off the chat feature, I'll never be done with the Service, and it will stay open forever. This seems less than optimal.
Long question short:
For a chat application that uses long polling to simulate push and immediate response, is it still best practice to use a Service to perform the HTTP queries, and store the information in a ContentProvider?
View 1 Replies
View Related
May 26, 2009
I want to download some data from internet.It should not block main UI thread. I know both thread and service can handle the work. What is the difference between them?
View 4 Replies
View Related
Oct 6, 2010
I have an application which requires networking service. I took on LWUIT4IO and adjusted it to my needs so now i have a network queue that can run one or more network threads.Now, my application is based on single root activity that spawns other child activities as needed (it's a reservation center for vacations, car rental etc.. each in it's own activity). The network is common to all and should be used by all activities. the network thread requires, basically, a callback to notify it's finished and return the result (input stream or byte array) .At first i thought that i should use a service instead of a singleton that will be started in the root activity(the service will also be started in the root activity), however working with a local service is problematic for me: 1. no callbacks which makes me use intents to encapsulate the request esponse in intents time consuming, also since there is not single point of listening (i have to use BroadcastReceivers)i have to add a calling class name or some other identifier so the sender of the request will know it's for him, i think this is also a waste of time and resources since i need only one listener.
i think i CAN use callbacks if i use Binder object to return local instance of my Service and then use the queuing method directly, this is problematic for me as acquiring Binder object is asynchronous and i need it 'on the spot' 3. I thought of using a static instance of the service and null it in onDestroy of the service, but if i use that way, i'm not so sure i need a service... 4. i saw a small answer in stackoverflow about inheriting application and putting whatever member you need there so when you use getApplication you get this instance and then you can retrieve whatever you want, is this even advisable ?
View 5 Replies
View Related
Nov 14, 2010
I am developing an Android app and I am doing some heavy work (bringing data from an online web page and parsing it to store in database) in a service. Currently, it is taking about 20+ mins and for this time my UI is stuck. I was thinking of using a thread in service so my UI doesn't get stuck but it is giving error.
View 1 Replies
View Related
Jun 23, 2010
I am starting to develop a new app and I am a bit confused about the structure I need to give it.I need to react to broadcast intents, so I placed a broadcast received in the manifest. Every single intent produces an action to be performed. Now the first question: should I start a service (maybe with non_sticky option?) or should I start a thread (or an async task) directly from the broadcast receiver? If I start a service, should I do all the stuff in its body, or should it start a thread. I should do the heavy job in a thread if there are time consuming operations, but what if the gui of my application is just an activity with the options and a button to start the service. What is the point in keeping the main thread busy? Do I risk to be killed for not being responsive? I read here and there that I can update the gui from a background thread. Can I do that even if it is started from a service? The AsyncTask's onProgressUpdate is said to run in the application main thread, but if the application is made of different activities, who tells me which activity is the user looking at while the thread is doing all its long work? The user could change activity in the meanwhile and then the update would be unuseful.I know it's (quite) a lot of questions, but I need to get some clarifications before taking the wrong path.
View 5 Replies
View Related
Sep 16, 2010
My IntentService is blocking my UI thread and I wanted to find out why. So I turned on profiling in the onStartCommand method of the IntentService and turned it off at the end of the onStartMethod. The working being done in between is web access with the Apache HTTP client.According to the profiler, the onStartCommand method of the IntentService is running on the main thread, not in a worker thread. Any idea what could cause this behavior?
View 3 Replies
View Related
Jul 27, 2009
i have a little frontend showing a list of items that it will retrieve from a service. I want that service to be started in a separate thread.so the UI is still responding to user interaction while waiting for that service to call a callback method. What is the best way to start the service in a detached thread?
View 6 Replies
View Related
Jul 5, 2010
I am a newbie in android and i had a question whether i should use a service or thread for http connection and what will be the advantage of using a service over a thread or viceversa. Please help me out with this.
View 13 Replies
View Related
Jun 24, 2010
HTo be able to write "nice" code between my application/activies and a local service I need to understand some basic Android concepts:What I'm wondering is if my application (as in my activities) and my local service is sharing one thread. I.e. when the activities and the local service executes tasks queued are these tasks interleaved in ONE thread thus sharing the thread or does the service has a thread of its own?Also if the local service shares the thread with the activities and the local service makes a direct call (via a callback) to one of the activities (i.e. no post message) is the activity thread "halted" or is the execution of that specific function queued to be executed later anyway?
View 1 Replies
View Related
Nov 7, 2010
I have an application that starts on boot using a broadcast receiver, also I have an activity and a process, because the service must run always on the background I am starting the service on it's own process using the android:process manifest tag.The ui is only for presentational needs and I would like the user to be able to run the service even if the activity is not active.when I press the back button or the home button the activity's on destroy method is called and the service although seems its running (it appears on the task manager) its not behaving as supposed, it should connect to the net and send some data but every X time using an timer task but the task never fires so the data are never send.
View 1 Replies
View Related
Nov 13, 2010
I need to create a service that runs a piece of code in new thread after (let us say) 10 mins. How can I do that? I have service ready but I don't seem to understand how (if ) to call timer from within thread.
View 3 Replies
View Related
Oct 5, 2010
can someone please help me? I would like to write a program which uses a service to periodically update a text view on an activity. I do this by having ActivityA with a 2 buttons to start/stop my service. In the service I run a timer which triggers every second. From here I need to have this launch and update a text view on ActivityB which at present is just a counter value.I'm sure there are likely better ways to do this, such as using only one activity, maybe using a thread but the main design consideration is to have the service running even if my activity is destoyed (the counter value would instead go trigger some alarm or file write instead of a text view update). Sorry for rambling. I find the android developer resources offer too many solutions!
View 2 Replies
View Related
Jun 1, 2010
I'm trying to think of a way on how to sync in between a local service and the main activity.
The local service has,
A thread with a socket connection that could receive data at any time.
A list/array with data.
At any time the socket could receive data and add it to the list.
The activity needs to display this data. So when the activity starts up it needs to attach or start the local service and fetch the list. It also needs to be notified if the list is updated.
I think I would need to sync my list somehow so the local service does not add a new entry to it while the activity fetches the list when connecting to the service.
View 2 Replies
View Related
Jun 23, 2010
I'm doing an application that requires that certain thread access data that's shared among it and another service.How can I protect these shared data form accessing in the same time is there anything in android for that or android has nothing to do with this as Java API's will do the job.
View 7 Replies
View Related
Jul 16, 2010
What is the difference between Service, Async Task & Thread. If i am not wrong all of them are used to do some stuff in background. So, how to decide which to use and when?
View 2 Replies
View Related
Sep 14, 2010
Suppose I have code in the onStart() handler of my Service to launch a thread to do some stuff and then call stopSelf().stopSelf() gets called before the thread finishes.What exactly happens?I've tested this out myself and my thread continues to execute until it is finished.Does Android hear the stopSelf() call, but postpone it until the thread is finished?
View 1 Replies
View Related
Aug 31, 2010
I have a service from which a start a new thread. This new thread will communicate with a TCP server using socket. What is the best way to send the data received from TCP server back to the service? Handlers or something else?
View 1 Replies
View Related
May 28, 2010
A new question about android and services. Currently I'm developing a App that should send images to a server. It should also be possible to send more images parallel. I made a service that creates for every image a new image. The activity can bind to that service and gather information about the progress. I want to show the current status for every image in a notification (and when the user clicks a notification, an activity with the progress for that image should be shown). But I get several problems with that approach. There are errors with binding, the notification pending event starts the activity completely new, so I lose information about currently sending images and so on. How I could design in a appropriate way.
View 1 Replies
View Related
May 26, 2009
I'm implementing a service that contains a thread to handle all time consuming operation. My core service logic is in a different thread than the ui or main thread. According to the Android document, when the OS plans to free some system resource, it will call onDestroy () on the service and only when onDestroy() returns it will kill the process hosting the service, thus giving opportunity to the service to cleanup.Now, when onDestroy() is called, I want to send a message to my service thread to do the necessary cleanup. Only when the service thread acknowledges that the cleanup or shutdown is complete, onDestroy () should return. I could find a way to send asynchronous messages to threads and the corresponding processing of the messages, but not able to figure out how I need to implement onDestroy(), such that it would send a message to the service thread and should wait for a result, before returning.
View 13 Replies
View Related
Jul 21, 2010
When you do a Thread.currentThread().getId(), is the resulting thread id scoped per process or scoped to the current Activity/Service?
View 1 Replies
View Related
Mar 4, 2010
This tutorial uses service to avoid any ANR timeouts. I just wonder, can I use Thread instead of service to do the work of getting data and updating RemoteViews? I don't want to create a service, because Thread is easier to handle and pass data into Thread.
View 2 Replies
View Related
Sep 7, 2010
How can I implement a run() method of thread if I create a Thread Global?
I mean If I create a Thread Globally then can I implement its run() method {" public void run()"} anywhere in my Application?
In the run() method I have to write the code to perform some action.
IF I can do it then please can anyone show me briefly how to do it particularly.
View 2 Replies
View Related
May 21, 2009
I am writing an application in which i need to handle messages between the main thread(the deafult UI related thread) and the user created Gamethread.
The requirement is like this.
An activity(say "Activity_X") is setting the view by "setContentView(some "View_Y")". In "Activity_X" i have implemeted "onCreateOptionsMenu()" and "onOptionsItemSelected()" fucntions for creating menus & a switch case for action to be taken on selecting those menus.Menu has items like "resume/pause/zoom/" .
All action to be take on selecting these menus are implemented in "View_Y" in a separate Gamethread by extending "Thread" class.
So whenever a menu is selected in "Activity_X" i need to send a message to "View_Y". And on receiving this ,a particular action/method should be called in View_Y(GameThread).
How can i achieve this using Handlers?Is there any other way of doing this? Please do share with me some code snippets for these.
View 3 Replies
View Related