Android :: Service Running On Seperate Thread
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
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
Apr 5, 2010
I have the following code running on my Android device. It works great and displays my list items wonderfully. It's also clever in the fact it only downloads the data when it's needed by the ArrayAdapter. However, whilst the download of the thumbnail is occurring, the entire list stalls and you cannot scroll until it's finished downloading. Is there any way of threading this so it'll still scroll happily, maybe show a place holder for the downloading image, finish the download, and then show?
I think I just need to put my downloadImage class into it's own thread so its executed separately from the UI. But how to add this into my code is the mystery!
CODE:........................
View 3 Replies
View Related
Nov 4, 2010
I've created a class which is an extension of Thread. This class hits a web service and throws some data on screen. I don't care about persisting this data (the screen displays search results).
Currently, the user simply types into an EditText and clicks a search button. I'd like to take away the search button and implement something similar to Google's Instant Search where, as you type, the search results get updated.
This means, as the user types, the search parameters change. I want to be able to kill the currently running thread (if one is currently running) and spawn a new one with the new search string. How can this be achieved? Can I do it with Thread or will I need to use a new object?
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 22, 2009
I am using this method to identify if a thread is running at any point of time, irrespective of whether the enclosing activity is running or not. Is this the right way?
View 3 Replies
View Related
Jul 20, 2010
I am continuously running a thread in my activity which fetches lat/ lon information and the overlays on the map are updated dynamically through a handler. The overlays can be varying in number and can change dynamically. The thread is interrupted in onPause().
I am over riding the onTap() method in my Itemizedoverlay, where I want to call a dialog or may be start anothrer activity which describes that particular overlay item.
Every time I click on the moving overlay my app force closes.
I am basically using same onTap() method in http://developer.android.com/resources/tutorials/views/hello-mapview.... .
If it is only a Toast message and not starting a dialog/activity then it works fine.
View 3 Replies
View Related
Jun 17, 2010
I want to stop currently running thread but -Thread.stop() - Thread.destroy() are DEPRECATED so can any one tell me how to stop the Thread .
View 6 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
Feb 19, 2010
Can someone advise the am command (for adb shell) to run junit tests in the main thread please? The following shows onStart etc running in the test runner thread. am instrument -w -e class co.uk.telesense. tests.MyTest co.uk.telesense.tests/android.test.InstrumentationTestRunner Ewan Benfield ttp://www.telesense.co .uk tel: 0845 643 5691 (+44 845 643 5691) mob: +44 (0) 77859 26477
View 2 Replies
View Related
Jul 13, 2010
I have a situation where i want to show a dialog. However, the code that calls the method to show the dialog can be running either in the ui thread or not. How can i find if the current thread is running in the ui thread or not?
View 12 Replies
View Related
Feb 17, 2010
is there any way to leave a thread in background when i close the app in android? I read about a Service but implementing it is too much than i need.
View 2 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
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
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
Nov 24, 2010
Have to create thread and run it for 5 seconds, then I want to stop. How can I do that? I can't do anything with time/milliseconds.
View 3 Replies
View Related
Aug 11, 2010
I'm develop a download manager function which the dialog will popup when the the item was finished download. the download function was running at background.
My question is how can I know when the downloading was finished and the project is intent other activity?
For example:
CODE:............
The above method where should I put? i try put it at onResume(), onStart() in every activity which will open by user. but unlucky it won't work.
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 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
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