Android Process and Resource managment
-
As Per My Knowledge, In Android when Application is start , Os assign new process to app and app will running in that UIThread (mainthead) of that process. so operation which is define under Activity Class will run on UiThread ( if we will not create separate class for any operation). and if we perform long running process we will do that task under the Service class ( Service is running even App will kill ).. So Service is running on UiThread or separate Thead? if it runs under UiThread then Why it is not affect to Ui OR if it runs under separate Thread then why we are creating another separate thread in service for long running operations?
-
Answer:
In Android when Application is start , Os assign new process to app Correct. app will running in that UIThread (mainthead) of that process Incorrect. An "app" does not run on any thread. Methods of Java objects are called on threads. so operation which is define under Activity Class will run on UiThread Incorrect. A Java class does not run on any thread. Methods of Java objects are called on threads. Hence, methods of an activity will be called on threads. Some of those methods will be called on the main application thread (a.k.a., UI thread) of the Android app's process. So Service is running on UiThread or separate Thead? Neither, or both, depending upon how you want to look at it. Again, a Java class does not run on any thread. Methods of Java objects are called on threads. The lifecycle methods of a service (e.g., onCreate(), onStartCommand(), onDestroy()) are called on the main application thread. onHandleIntent() of an IntentService is called on a background thread. if it runs under UiThread then Why it is not affect to Ui Any time you spend in your code on the main application thread will freeze the UI. It does not matter whether the code is a method on an activity, a method on a service, or a method on something else. if it runs under separate Thread then why we are creating another separate thread in service for long running operations? To avoid tying up the main application thread and thereby freezing the UI.
Hardik Gajera at Stack Overflow Visit the source
Other answers
Services runs on UI thread. Also in some way it can interact with UI. Here is a good starting article. http://developer.android.com/guide/components/services.html
Alexander Myznikov
Related Q & A:
- How to read text off an embedded text resource?Best solution by Stack Overflow
- How to create new process as its own parent process?Best solution by Stack Overflow
- Which university are best or better to do for international health managment/policy?Best solution by Yahoo! Answers
- IS hospitality managment a good career?Best solution by Yahoo! Answers
- Is business managment difficult?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.