Skip to content

Self Implemented Async Task, cause Async Task is deprecated

Notifications You must be signed in to change notification settings

ch8n/AsyncTasker

Repository files navigation

AndroidBites

✋ About

Hola Amigos! 🙌, welcome to my coding playground! go on explore around 👩‍💻

Do let me know if you find something useful or want to suggest some improvement also don't forget to checkout of blogs at chetangupta.net

👀 Social

LinkedIn | Medium | Twitter | StackOverflow | CodeWars | Portfolio | Github | Instagram | Youtube

AsyncTasker

Pooja's AsyncTask Challenge Self Implemented Async Task for Pooja Srivs Challenge

API design

This is a sample project api design is similar to that of asyncTask,

abstract class AsyncTasker<Params, Progress, Result> {

    abstract fun doInBackground(vararg many: Params): Result
    abstract fun onPostExecute(data: Result)
    abstract fun onPreExecute()
    abstract fun onProgressUpdate(progress: Progress)
    
    /** Extra function that is called when every task complete **/
    abstract fun onCompleted(isInterrupted: Boolean)

    /** controller function **/
    fun execute(vararg many: Params) {
      ... doing stuff
    }

    /** function that interrupt underlying worker thread for immediate cancel of task **/
    fun cancel() {
       ... doing stuff
    }
}

Behind the Back uses HandlerThread as worker thread and handler to perform the task.

Sample

  1. click fab to perform async task
  2. long click fab to perform cancel async task

TODO

  • test cases
  • flag to check background task is active

👮 License

Shield: CC BY-SA 4.0

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

CC BY-SA 4.0

About

Self Implemented Async Task, cause Async Task is deprecated

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages