SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Good-bye progress dialog mess
tsuyoyo (@tsuyogoro)
Mercari, Inc.
About me
tsuyoyo (@tsuyogoro)
Android engineer
Mercari, Inc
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
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
My experiences
● Tough to fix bugs
● Fix would make code dirty
● Galaxy S7
How can we beat them?
● android:configChanges="orientation"
● No care (e.g. call API again)
● Try to manage state
○ Activity#onSaveInstanceState
○ Activity#onRetainCustomNonConfigurationInstance
1. Something independent on Activity lifecycle
2. Always view can revive
3. Dialog? (not DialogFragment)
My idea
time
Calling API
ViewModel
View
Implementation idea (1) : BehaviorSubject
onNext(true);
BehaviorSubject
<Boolean>
Observer B
onNext(false);
Observer C
Observer A
My idea
time
Calling API
ViewModel
View
onNext
(in progress)
onNext
(complete)
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/
Custom scope
● Looks just annotation, no effect
● Application class holds the component, releases it at
end of screen
@Scope
@Retention(RetentionPolicy.RUNTIME)
@interface ViewModelScope {
}
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;
}
}
Custom scope
public class MainActivity extends AppCompatActivity {
@Inject MyViewModel myViewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
…
((MyApplication) getApplication()).getMyComponent().inject(this);
bindViewModel();
}
@Override
public void finish() {
super.finish();
((MyApplication) getApplication()).releaseMyComponent();
}
Summary
● Simple way to beat messy caused by ProgressDialog
● BehaviorSubject & CustomScope
● For detail
○ https://github.com/tsuyoyo/shibuya_apk_13
Implementation idea (1) : BehaviorSubject
private MyFakeApi api;
private BehaviorSubject<Boolean> isLoading = BehaviorSubject.create(false);
...
public Observable<Boolean> isLoading() { return isLoading.asObservable(); }
…
api.call().
.doOnSubscribe( () -> isLoading.onNext(true) )
.doOnUnsubscribe( () -> isLoading.onNext(false) )
.subscribe( /** do something */ )
...
private void bindViewModel() {
…
myViewModel.isLoading()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(isLoading -> /** show/dismiss progress dialog */)
ViewModel
View

Weitere ähnliche Inhalte

Ähnlich wie Goodbye progress dialog mess on Android

Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
guest092df8
 

Ähnlich wie Goodbye progress dialog mess on Android (20)

Error handling
Error handlingError handling
Error handling
 
FirefoxOS Window Management
FirefoxOS Window ManagementFirefoxOS Window Management
FirefoxOS Window Management
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golang
 
Modern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxModern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptx
 
Griffon demo
Griffon demoGriffon demo
Griffon demo
 
Introduction to Android - Session 3
Introduction to Android - Session 3Introduction to Android - Session 3
Introduction to Android - Session 3
 
Introduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerIntroduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debugger
 
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQ
 
Web-development-git
Web-development-gitWeb-development-git
Web-development-git
 
Javascript training sample
Javascript training sampleJavascript training sample
Javascript training sample
 
Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and Jetpack
 
Ext GWT - Overview and Implementation Case Study
Ext GWT - Overview and Implementation Case StudyExt GWT - Overview and Implementation Case Study
Ext GWT - Overview and Implementation Case Study
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragments
 
Front-End Engineering
Front-End EngineeringFront-End Engineering
Front-End Engineering
 
Micronaut: A new way to build microservices
Micronaut: A new way to build microservicesMicronaut: A new way to build microservices
Micronaut: A new way to build microservices
 
Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
 
Redmine @ Mippin
Redmine @ MippinRedmine @ Mippin
Redmine @ Mippin
 
Java Performance: What developers must know
Java Performance: What developers must knowJava Performance: What developers must know
Java Performance: What developers must know
 
Multi screenlab
Multi screenlabMulti screenlab
Multi screenlab
 
Using FXML on Clojure
Using FXML on ClojureUsing FXML on Clojure
Using FXML on Clojure
 

Kürzlich hochgeladen

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 

Kürzlich hochgeladen (20)

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 

Goodbye progress dialog mess on Android

  • 1. Good-bye progress dialog mess tsuyoyo (@tsuyogoro) Mercari, Inc.
  • 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
  • 5. My experiences ● Tough to fix bugs ● Fix would make code dirty ● Galaxy S7
  • 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)
  • 9. Implementation idea (1) : BehaviorSubject onNext(true); BehaviorSubject <Boolean> Observer B onNext(false); Observer C Observer A
  • 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; } }
  • 14. Custom scope public class MainActivity extends AppCompatActivity { @Inject MyViewModel myViewModel; @Override protected void onCreate(Bundle savedInstanceState) { … ((MyApplication) getApplication()).getMyComponent().inject(this); bindViewModel(); } @Override public void finish() { super.finish(); ((MyApplication) getApplication()).releaseMyComponent(); }
  • 15. Summary ● Simple way to beat messy caused by ProgressDialog ● BehaviorSubject & CustomScope ● For detail ○ https://github.com/tsuyoyo/shibuya_apk_13
  • 16.
  • 17. Implementation idea (1) : BehaviorSubject private MyFakeApi api; private BehaviorSubject<Boolean> isLoading = BehaviorSubject.create(false); ... public Observable<Boolean> isLoading() { return isLoading.asObservable(); } … api.call(). .doOnSubscribe( () -> isLoading.onNext(true) ) .doOnUnsubscribe( () -> isLoading.onNext(false) ) .subscribe( /** do something */ ) ... private void bindViewModel() { … myViewModel.isLoading() .observeOn(AndroidSchedulers.mainThread()) .subscribe(isLoading -> /** show/dismiss progress dialog */) ViewModel View