Obtain results at screen transition destination using RxJava on Android

Asked 2 years ago, Updated 2 years ago, 28 views

TITLE As it stands, how does RxJava and RxAndroid get results for patterns that start asynchronous processing with FirstActivity on Android and receive results with transitioned SecondActivity?Is there no other way but to create these patterns on the part of the user, rather than on the library that is considered?Please let me know.

android

2022-09-30 11:21

1 Answers

I think there are several implementation approaches, but I often use the following two:

  • Set Observable to Hot in FirstActivity (I often use replay or BehaviorSubject)
  • Give Observable to the Application Class and issue a key at that time
  • SecondActivity uses the key to remove it from the Application class after the screen transition
  • Create a Service that is responsible for asynchronous processing itself
  • Request FirstActivity to Start Communication with Service
  • Bind on the SecondActivity side and wrap it so that it can be treated as Observable

1 is easy to implement, but it is not suitable for critical processing because handling is troublesome if the activity transition is not successful.I think it is difficult to implement 2 while the service can bear the responsibility.
When I implement it, I try to use the approach of 1 for retries and 2 for those that require precise health management.


2022-09-30 11:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.