2
Reply

How to create a service with single thread?

Satheesh Reddy

Satheesh Reddy

11y
3.4k
1
Reply

    http://skillgun.com/question/608/android/threads/how-to-create-a-service-with-single-thread-should-i-use-intentservice-or-asynctask

    A small code snipphet to demonstrate how to create a service using threads.

    A thread is created first using the Thread Class, the object of which is then used to initiate and create the service.

    Start method is used to create and execute the thread, hence invoking the service

    1. public static Thread demo(final Runnable runnable) {
    2. final Thread t = new Thread() {
    3. @Override
    4. public void run() {
    5. try {
    6. runnable.run();
    7. } finally {
    8. }
    9. }
    10. };
    11. t.start();
    12. return t;
    13. }