Date post: | 13-Aug-2015 |
Category: |
Software |
Upload: | jiahaoliuliu |
View: | 137 times |
Download: | 0 times |
Problem with mobile
UI screen as observer
Observable could return data in any moment
UI screen could not be in foreground
It cannot modify the view of another UI screen
Shop closedJust leave the package in the mail
box.
When the shop opens again, the package will be checked
Postman Activity
Abstract class
Implements Observer
protected boolean isInForeground
Updated by onResume() and onPause()
Postman Activity
protected abstract void processDataIfExists()
Called onResume()
1. If the data does not exists, finish
2. Otherwise, process the data
3. And remove the data
Activities
Extends from PostmanActivity
Implements processDataIfExists()
Implements update(Observable, Object)
If (isInForeground) processDataIfExists()
observable.deleteObserver(this)
User case
MainActivity extends from PostmanActivity
1. MainActivity request data to PostmanObservable
2. PostmanObservable register the observer
3. PostmanObservable prepare the data and notify to MainActivity
User case
Update from MainActivity is called
1. Save the data
2. If MainActivity is in foreground
Invoke processDataIfExist()
User case
Update from MainActivity is called
3. If MainActivity is not in foreground
Do nothing
When the MainActivity goes on foreground
Invoke processDataIfExist()
4. Delete itself from the observable
Sample code herehttps://github.com/jiahaoliuliu/
PostmanPattern/tree/simplePostmanPattern