3. About this talk
● Progress dialog
● Technically
○ Show/Dismiss by BehaviorSubject (RxJava 1.x)
○ ViewModel lifecycle management with Dagger2
● Preview app
○ https://github.com/tsuyoyo/shibuya_apk_13
4. Major troubles by progress dialog...
● Dismiss at orientation change
● Remains on screen
● Suddenly crashes in the background
(since 3.0/HoneyComb)
java.lang.IllegalStateException:
Can not perform this action after onSaveInstanceState
6. How can we beat them?
● android:configChanges="orientation"
● No care (e.g. call API again)
● Try to manage state
○ Activity#onSaveInstanceState
○ Activity#onRetainCustomNonConfigurationInstance
7. 1. Something independent on Activity lifecycle
2. Always view can revive
3. Dialog? (not DialogFragment)
11. Implementation idea (2) : Lifecycle of ViewModel
● Use Dagger2, provided by component
● Scope?
○ longer than Activity & shorter than Application
● Custom scope!!
○ Referred : Dependency injection with Dagger 2 - Custom scopes
http://frogermcs.github.io/dependency-injection-with-dagger-2-custom-scopes/
12. Custom scope
● Looks just annotation, no effect
● Application class holds the component, releases it at
end of screen
@Scope
@Retention(RetentionPolicy.RUNTIME)
@interface ViewModelScope {
}
13. Custom scope
public class MyApplication extends Application {
private MyComponent component;
public MyComponent getMyComponent() {
if (component == null) {
component = DaggerMyComponent.builder().build();
}
return component;
}
public void releaseMyComponent() {
component = null;
}
}
15. Summary
● Simple way to beat messy caused by ProgressDialog
● BehaviorSubject & CustomScope
● For detail
○ https://github.com/tsuyoyo/shibuya_apk_13