Skip to content
This repository was archived by the owner on Dec 17, 2020. It is now read-only.

Commit d49073a

Browse files
committed
Small documentation fixes.
1 parent 1595db8 commit d49073a

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

DOCUMENTATION.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ public class Main extends TaskActivityCompat implements Task.Callback {
170170
---
171171
Besides the basics there are some more advanced API's you will probably need.
172172

173-
####**1. Getting the task result**
173+
#### **1. Getting the task result**
174174
Unlike the default Android `AsyncTask` implementation you don't get `Task` results as a parameter, instead you will need to call the `Task.getResult()` method, which returns the tasks result.
175175

176-
####**2. Getting the task state**
176+
#### **2. Getting the task state**
177177
The Android `AsyncTask` API provides the `AsyncTask.getStatus()` method which returns an enum value which can be used to determinate the tasks current state. Instead of using that method combined with an enum you can use on of the following methods:
178178

179179
* `isFinished()`
@@ -182,16 +182,16 @@ The Android `AsyncTask` API provides the `AsyncTask.getStatus()` method which re
182182
* `isResultDelivered()`
183183
* `isCanceled()`
184184

185-
####**3. Getting the task last progress update**
185+
#### **3. Getting the task last progress update**
186186
To get the tasks most recent progress update use the `getLastKnownProgress()` method, this method returns null when no last know progress is available.
187187

188-
####**4. AdvancedCallback**
188+
#### **4. AdvancedCallback**
189189
If you need the `onProgressUpdated` and `onCanceled` callback methods you can implement the `AdvancedCallback` interface, which is an extension of the `Callback` interface.
190190

191-
####**5. Annotations outside Activities or Fragments**
191+
#### **5. Annotations outside Activities or Fragments**
192192
By default annotated methods are only resolved if they are added to a `TaskActivityCompat` or `TaskFragmentCompat`, but you can register custom classes using the `TaskActivityCompat.bindTaskTarget()` method you must call this method as soon as possible, for example in the constructor of the Activity to prevent missing callbacks. You obviously need to re-register the object when a configuration change occurs like rotation.
193193

194-
####**6. TaskExecutor & Executor**
194+
#### **6. TaskExecutor & Executor**
195195
You can also execute tasks without using a `TaskManager` this means that you are responsible for removing and setting the `Callback` listener. Executing tasks without using the `TaskManager` is handy when you don't necessarily need to get any feedback to the user-interface.
196196

197197
```java
@@ -211,7 +211,7 @@ You can also use a custom java `Executor` to execute tasks with:
211211
TaskExecutor.executeOnExecutor(new ExampleTask(), yourExecutor);
212212
```
213213

214-
####**7. Using the TaskManagerLifeCycleProxy to mimic the TaskActivityCompat**
214+
#### **7. Using the TaskManagerLifeCycleProxy to mimic the TaskActivityCompat**
215215
If you already use some custom Activity or Fragment implementation you might not be able to use the `TaskActivityCompat` or `TaskFragmentCompat` class. To overcome this problem you can implement the behaviour of the `TaskActivityCompat` yourself using the `TaskManagerLifeCycleProxy` class.
216216

217217
Create a new `TaskManagerLifeCycleProxy` instance and let your Activity (or Fragment) implement the `TaskManagerOwner` interface. Override the`onStart()` and `onStop()` methods and proxy those together with the `getTaskManager()` method to the `TaskManagerLifeCycleProxy` instance.
@@ -249,7 +249,7 @@ public class MyBaseActivity extends SomeActivity implements TaskManagerOwner {
249249
## 3. How it works
250250
How this library works is not extremely complicated it can however be quite difficult to understand correctly if you have limited knowledge about the Android Activity and Fragment life-cycle and how Android manages these objects.
251251

252-
####**How are task objects retained?**
252+
#### **How are task objects retained?**
253253
The first thing to understand is how `Task` objects are kept alive when the Activity is destroyed by the system when a configuration change occurs (like rotation). Often used solutions include using static variables, the `Application` class or the `Activity.onRetainNonConfigurationInstance()` method to store objects in. These methods are however non optimal and Google suggests using the Fragment API in combination with `Fragment.setRetainInstanceState(true)` instead. Using the Fragment API avoids keeping objects alive after the Activity or Fragment is destroyed for good which can happen when the `Application` class or static variables are used. Google demonstrates the practise of using the Fragment API in combination with `setRetainInstanceState(true)` in the excellent [Android Architecture Lifecycle](https://developer.android.com/reference/android/arch/lifecycle/Lifecycle.html) library.
254254

255255
This library leverages the same principle and uses so called *"no-ui-fragments"* which are retained using `setRetainInstanceState(true)` to store objects in. The objects stored in these Fragments are `TaskManager` objects which in their turn store `Task` objects. The creation of these no-ui-fragments happens as soon as the first call to one of these methods is made:
@@ -263,17 +263,17 @@ This library leverages the same principle and uses so called *"no-ui-fragments"*
263263

264264
Essentially any time you request a `TaskManager`. You should however note that the library itself also internally calls these methods.
265265

266-
####**What about the Callback listeners?**
266+
#### **What about the Callback listeners?**
267267
Each `Task` has a listener attached to it (`Callback` interface), these listeners must not leak between Activity instances, especially since a listener might hold a reference to an Activity causing it to leak the Activity object. Therefor the `TaskManager` makes sure listeners must be removed from a task as soon as the Activity is being destroyed. A new listener is attached to the `Task` when the new Activity is created, so that the `Task` can still report it's result. To prevent Tasks from reporting their results before the Activity is started the `Callback` listeners are removed in `onStop()` and attached in `onStart()`.
268268

269269
The new listeners that need to be attached to a `Task` are acquired during `onStart()` the Activity (or Fragment) TaskManager will call the `onPreAttach(Task)` method which then should return the new listeners for that specific `Task`. When annotations are used `Callback` listeners are automatically generated at compile time and automatically attached to `Tasks` so there is no need to override `onPreAttach(Task)`.
270270

271-
####**What happens when a Task without Callback finishes?**
271+
#### **What happens when a Task without Callback finishes?**
272272
When a `Task` does not have a `Callback` listener attached to it (after `onStop()` and before `onStart()` is called) it will skip/wait with the delivery and deliver the results as soon as a new listener is attached. This happens right after the `onPreAttach(Task)` method returns, as the `TaskManager` will immediately attach the newly provided `Callback` listener to the `Task` and the `Task` can immediately fire the listener if it was waiting for it. Because this all happens during the Activity or Fragment `onStart()` you need to be sure that at this point the user-interface is ready. If you manually call one of the `TaskManager.attach()` methods a `Task` might also immediately fire the new listener.
273273

274274
**Important:** Only the `onPostExecute()` and `onCanceled()` methods will wait for delivery, other method's like `onProgressUpdate` won't wait for delivery and will be skipped if no `Callback` listener is attached to the `Task`. You can restore a tasks progress using the `Task.getLastKnownProgress()` method.
275275

276-
####**How does the Task and Callback life-cycle work?**
276+
#### **How does the Task and Callback life-cycle work?**
277277
A `Task` basically has four life-cycle methods *(its heavily based on Android's AsyncTask)*:
278278

279279
* `onPreExecute()` *[ui-thread]*

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ dependencies {
6060
}
6161
```
6262

63+
Because of the dependency on Google's new Architecture Lifecyle library you must add Google's maven repository to your top-level build.gradle file (if you did not already do this).
64+
```groovy
65+
allprojects {
66+
repositories {
67+
maven { url 'https://maven.google.com' }
68+
}
69+
}
70+
```
71+
6372
## Why and when
6473

6574
*When and why should I use this library?* Always! its awesome! No, obviously you should not always use this library. **This library is useful when you need to do things in the **background** which are heavily bound to the user-interface** like: Refreshing a list which is populated from a database, loading an article from a network source or decoding an image, all those things are quit tightly bound to the user-interface and when the device rotates you don't want to cancel this work or do it again. If you need: task scheduling, automatic retries, task persistence across reboots, task constrains etc. then you need to use an additional library.

0 commit comments

Comments
 (0)