user2067201
user2067201

Reputation: 258

Process and threads in android

Can service and activity run in same linux process at the same time.?

private class Test extends  Service{
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    new Thread(new Runnable() {

        @Override
        public void run() {
            // Computational logic

        }
    }).start();


    return super.onStartCommand(intent, flags, startId);
}

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

}

Does the the thread execute in new linux process or the same process which call this service(UI process)?.

Upvotes: 0

Views: 202

Answers (2)

Aman Gautam
Aman Gautam

Reputation: 3579

From the documentation: http://developer.android.com/reference/android/app/Service.html

A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.

A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).

Unless you mention in manifest, the service will run in the same thread: See here: http://developer.android.com/guide/topics/manifest/service-element.html

Upvotes: 1

Andy Res
Andy Res

Reputation: 16043

By default every application runs in its own process and all components of the application run in that process.

Can service and activity run in same linux process at the same time.?

The above statement already answer this question, and here's what Services docs one more time says:

The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.

For further reading consider this link: http://developer.android.com/guide/components/processes-and-threads.html

Upvotes: 1

Related Questions