SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
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
Goodbye progress dialog mess on Android
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

Contenu connexe

Similaire à Goodbye progress dialog mess on Android

FirefoxOS Window Management
FirefoxOS Window ManagementFirefoxOS Window Management
FirefoxOS Window ManagementAlive Kuo
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golangSeongJae Park
 
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.pptxMd Shamsul Arafin Mahtab
 
Introduction to Android - Session 3
Introduction to Android - Session 3Introduction to Android - Session 3
Introduction to Android - Session 3Tharaka Devinda
 
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 debuggerNaoto Ono
 
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQLuke Luo
 
Javascript training sample
Javascript training sampleJavascript training sample
Javascript training sampleprahalad_das_in
 
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 JetpackSunita Singh
 
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 StudyAvi Perez
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragmentsVitali Pekelis
 
Front-End Engineering
Front-End EngineeringFront-End Engineering
Front-End EngineeringSaad Talaat`
 
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 microservicesLuram Archanjo
 
Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxuiguest092df8
 
Java Performance: What developers must know
Java Performance: What developers must knowJava Performance: What developers must know
Java Performance: What developers must knowDiego Lemos
 
Using FXML on Clojure
Using FXML on ClojureUsing FXML on Clojure
Using FXML on ClojureEunPyoung Kim
 

Similaire à 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
 

Dernier

Flutter GDE session GDSC ZHCET AMU, aligarh
Flutter GDE session GDSC ZHCET AMU, aligarhFlutter GDE session GDSC ZHCET AMU, aligarh
Flutter GDE session GDSC ZHCET AMU, aligarhjamesbond00714
 
Governors ppt.pdf .
Governors ppt.pdf                              .Governors ppt.pdf                              .
Governors ppt.pdf .happycocoman
 
Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024
Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024
Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024California Asphalt Pavement Association
 
Wave Energy Technologies Overtopping 1 - Tom Thorpe.pdf
Wave Energy Technologies Overtopping 1 - Tom Thorpe.pdfWave Energy Technologies Overtopping 1 - Tom Thorpe.pdf
Wave Energy Technologies Overtopping 1 - Tom Thorpe.pdfErik Friis-Madsen
 
Support nodes for large-span coal storage structures
Support nodes for large-span coal storage structuresSupport nodes for large-span coal storage structures
Support nodes for large-span coal storage structureswendy cai
 
introduction to python, fundamentals and basics
introduction to python, fundamentals and basicsintroduction to python, fundamentals and basics
introduction to python, fundamentals and basicsKNaveenKumarECE
 
Chapter 2 Canal Falls at Mnnit Allahabad .pptx
Chapter 2 Canal Falls at Mnnit Allahabad .pptxChapter 2 Canal Falls at Mnnit Allahabad .pptx
Chapter 2 Canal Falls at Mnnit Allahabad .pptxButcher771
 
EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...
EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...
EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...marijomiljkovic1
 
Evaluation Methods for Social XR Experiences
Evaluation Methods for Social XR ExperiencesEvaluation Methods for Social XR Experiences
Evaluation Methods for Social XR ExperiencesMark Billinghurst
 
عناصر نباتية PDF.pdf architecture engineering
عناصر نباتية PDF.pdf architecture engineeringعناصر نباتية PDF.pdf architecture engineering
عناصر نباتية PDF.pdf architecture engineeringmennamohamed200y
 
Tekom Netherlands | The evolving landscape of Simplified Technical English b...
Tekom Netherlands | The evolving landscape of Simplified Technical English  b...Tekom Netherlands | The evolving landscape of Simplified Technical English  b...
Tekom Netherlands | The evolving landscape of Simplified Technical English b...Shumin Chen
 
Injection Power Cycle - The most efficient power cycle
Injection Power Cycle - The most efficient power cycleInjection Power Cycle - The most efficient power cycle
Injection Power Cycle - The most efficient power cyclemarijomiljkovic1
 
Searching and Sorting Algorithms
Searching and Sorting AlgorithmsSearching and Sorting Algorithms
Searching and Sorting AlgorithmsAshutosh Satapathy
 
The Art of Cloud Native Defense on Kubernetes
The Art of Cloud Native Defense on KubernetesThe Art of Cloud Native Defense on Kubernetes
The Art of Cloud Native Defense on KubernetesJacopo Nardiello
 
Final PPT.ppt about human detection and counting
Final PPT.ppt  about human detection and countingFinal PPT.ppt  about human detection and counting
Final PPT.ppt about human detection and countingArbazAhmad25
 
This chapter gives an outline of the security.
This chapter gives an outline of the security.This chapter gives an outline of the security.
This chapter gives an outline of the security.RoshniIsrani1
 
zomato data mining datasets for quality prefernece and conntrol.pptx
zomato data mining  datasets for quality prefernece and conntrol.pptxzomato data mining  datasets for quality prefernece and conntrol.pptx
zomato data mining datasets for quality prefernece and conntrol.pptxPratikMhatre39
 

Dernier (20)

Flutter GDE session GDSC ZHCET AMU, aligarh
Flutter GDE session GDSC ZHCET AMU, aligarhFlutter GDE session GDSC ZHCET AMU, aligarh
Flutter GDE session GDSC ZHCET AMU, aligarh
 
Hydraulic Loading System - Neometrix Defence
Hydraulic Loading System - Neometrix DefenceHydraulic Loading System - Neometrix Defence
Hydraulic Loading System - Neometrix Defence
 
Governors ppt.pdf .
Governors ppt.pdf                              .Governors ppt.pdf                              .
Governors ppt.pdf .
 
Caltrans view on recycling of in-place asphalt pavements
Caltrans view on recycling of in-place asphalt pavementsCaltrans view on recycling of in-place asphalt pavements
Caltrans view on recycling of in-place asphalt pavements
 
Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024
Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024
Caltrans District 8 Update for the CalAPA Spring Asphalt Conference 2024
 
Wave Energy Technologies Overtopping 1 - Tom Thorpe.pdf
Wave Energy Technologies Overtopping 1 - Tom Thorpe.pdfWave Energy Technologies Overtopping 1 - Tom Thorpe.pdf
Wave Energy Technologies Overtopping 1 - Tom Thorpe.pdf
 
Update on the latest research with regard to RAP
Update on the latest research with regard to RAPUpdate on the latest research with regard to RAP
Update on the latest research with regard to RAP
 
Support nodes for large-span coal storage structures
Support nodes for large-span coal storage structuresSupport nodes for large-span coal storage structures
Support nodes for large-span coal storage structures
 
introduction to python, fundamentals and basics
introduction to python, fundamentals and basicsintroduction to python, fundamentals and basics
introduction to python, fundamentals and basics
 
Chapter 2 Canal Falls at Mnnit Allahabad .pptx
Chapter 2 Canal Falls at Mnnit Allahabad .pptxChapter 2 Canal Falls at Mnnit Allahabad .pptx
Chapter 2 Canal Falls at Mnnit Allahabad .pptx
 
EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...
EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...
EJECTOR REFRIGERATION CYCLE WITH THE INJECTION OF A HIGH DENSITY FLUID INTO A...
 
Evaluation Methods for Social XR Experiences
Evaluation Methods for Social XR ExperiencesEvaluation Methods for Social XR Experiences
Evaluation Methods for Social XR Experiences
 
عناصر نباتية PDF.pdf architecture engineering
عناصر نباتية PDF.pdf architecture engineeringعناصر نباتية PDF.pdf architecture engineering
عناصر نباتية PDF.pdf architecture engineering
 
Tekom Netherlands | The evolving landscape of Simplified Technical English b...
Tekom Netherlands | The evolving landscape of Simplified Technical English  b...Tekom Netherlands | The evolving landscape of Simplified Technical English  b...
Tekom Netherlands | The evolving landscape of Simplified Technical English b...
 
Injection Power Cycle - The most efficient power cycle
Injection Power Cycle - The most efficient power cycleInjection Power Cycle - The most efficient power cycle
Injection Power Cycle - The most efficient power cycle
 
Searching and Sorting Algorithms
Searching and Sorting AlgorithmsSearching and Sorting Algorithms
Searching and Sorting Algorithms
 
The Art of Cloud Native Defense on Kubernetes
The Art of Cloud Native Defense on KubernetesThe Art of Cloud Native Defense on Kubernetes
The Art of Cloud Native Defense on Kubernetes
 
Final PPT.ppt about human detection and counting
Final PPT.ppt  about human detection and countingFinal PPT.ppt  about human detection and counting
Final PPT.ppt about human detection and counting
 
This chapter gives an outline of the security.
This chapter gives an outline of the security.This chapter gives an outline of the security.
This chapter gives an outline of the security.
 
zomato data mining datasets for quality prefernece and conntrol.pptx
zomato data mining  datasets for quality prefernece and conntrol.pptxzomato data mining  datasets for quality prefernece and conntrol.pptx
zomato data mining datasets for quality prefernece and conntrol.pptx
 

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
  • 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