package BWP.MobileSale;

import java.util.concurrent.Callable;

import android.os.AsyncTask;
import android.util.Log;

public abstract class BackRunTask implements Callable<Object>{

    final String tag = "BackRunTask";
	
	Boolean mIsRunning = false;	
	
	protected void onTaskPreExecute()
	{
		
	}
	protected void onTaskPostExecute()
	{
		
	}
	protected void onTaskCancelled()
	{
		
	}
	
	public  void execute()
	{
		if(mIsRunning){
			Log.w(tag, "重复任务");
			System.out.println("重复任务");
			return;
		}
		new Task().execute();
	}
	
	
	class Task extends AsyncTask<Void,Void,Void>
	{

		@Override
		protected Void doInBackground(Void... params) {
			try {
				mIsRunning=true;
				call();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}

		@Override
		protected void onCancelled() {
			super.onCancelled();
			onTaskCancelled();
		}

		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);
			onTaskPostExecute();
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			onTaskPreExecute();
		}

	
		
	}
	
	
}
