package com.sjkj.base_lib.camera.dh.async;

import android.os.AsyncTask;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

/**
 * @description:
 * @author:111144
 * @date:2020/5/28
 */
public class AsyncLifecycleObserver implements LifecycleObserver {
    private AsyncBuilder asyncBuilder;
    public AsyncLifecycleObserver(AsyncBuilder asyncBuilder){
        this.asyncBuilder = asyncBuilder;
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void  onLifeCycleCreate() {
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void  onLifeCycleDestroy() {
        if (asyncBuilder != null && asyncBuilder.getStatus() != AsyncTask.Status.FINISHED){
            asyncBuilder.cancel(true);
        }
    }
}
