AbcThread.h
#include<utils/Thread.h>
Class AbcThread: public Thread
{
public:AbcThread();
virtual ~AbcThread();
protected:
virtual bool threadLoop();// Explain later for the return value}
AbcThread.cpp
#include<utils/Thread.h>#include<utils/Log.h>
AbcThread::AbcThread :Thread(false)// Thread inherit from RefBase.{ALOGD("Consctruct");}
AbcThread::~AbcThread
{ALOGD("Desctruct");}
AbcThread::ThreadLoop
{// Put what you want to do when thread is running here... return true or false;}
Main.cpp
#defineLOG_TAG"Main"#include<utils/Log.h>#include<utils/threads.h>#include"AbcThread.h"intmain(){
sp<AbcThread> thread = new AbcThread;// Note: Must write like this!
thread->run("AbcThread");// thread->run() is fine too }
// Derived class must implement threadLoop(). The thread starts its life
// here. There are two ways of using the Thread object:
// 1) loop: if threadLoop() returns true, it will be called again if
// requestExit() wasn't called.
// 2) once: if threadLoop() returns false, the thread will exit upon return.
virtual bool threadLoop() = 0;
How to write a native thread and how to use itAbcThread.h#include <utils/Thread.h>Class AbcThread: public Thread{public: AbcThread(); virtual ~AbcThread();protected: virtual bool threadLoop(); // Explain later for the return valu