Sep 12 | 8:20 AM |
Mark M. | has entered the room |
Sep 12 | 8:25 AM |
Mark M. | turned on guest access |
Sep 12 | 8:55 AM |
Scott W. | has entered the room |
Scott W. |
Hello!
|
Mark M. |
hi! sorry for the delay!
|
Mark M. |
how can I help you today?
|
Scott W. |
I'm working with chrome custom tabs today
|
Mark M. |
I have never used those, so my ability to help may be limited
|
Scott W. |
ok. I'll describe the problem.
|
Scott W. |
Activity A needs to kick off a chrome custom tab(CCT). When the CCT is closed, my app should return to Activity B.
|
Scott W. |
Or, Activity A should know that the CCT ended and finish itself
|
Scott W. |
Activity B is decided by a TaskStackBuilder that was created earlier.
|
Sep 12 | 9:00 AM |
Mark M. |
I don't know exactly what "ended" or "closed" means with respect to the CCT
|
Mark M. |
if you mean that the user was in the CCT, then pressed BACK, Activity A will know that it was restarted via lifecycle events
|
Scott W. |
CCT opens a chrome tab. There's an x in the top left that can be pressed to return to the activity that launched the CCT
|
Mark M. |
OK, same thing: Activity A can detect via lifecycle events that it was restarted
|
Mark M. |
assuming that Activity A also tracks whether it started the CCT, it can then know if it was restarted as part of coming back from the CCT
|
Scott W. |
ok so I can just set a boolean to check if the CCT was launched, then check that boolean in Activity A's onResume?
|
Mark M. |
yes, though you will want to track that boolean in the saved instance state Bundle, in case a configuration change occurs while the CCT is in the foreground
|
Scott W. |
ok
|
Scott W. |
all right I'll go with this solution.
|
Scott W. |
I have one more question about LiveData
|
Mark M. |
I know a lot more about LiveData than CCT, so that's promising! :-)
|
Sep 12 | 9:05 AM |
Scott W. |
I'm working on this SDK design, and trying to avoid exposing our custom Deferred objects.
|
Sep 12 | 9:05 AM |
Mark M. |
I seem to recall us discussing that in a past chat
|
Scott W. |
so, the app layer will call some method like user_get_contacts
|
Scott W. |
actually
|
Scott W. |
app layer will call getCallSurvey(int callId)
|
Scott W. |
normally, this method would return a Deferred object
|
Scott W. |
I've implemented it to return a MutableLiveData object
|
Scott W. |
a ViewModel object makes the call
|
Scott W. |
and an Activity registers itself as an observer through the ViewModel.
|
Scott W. |
the actual data is a String directing the user to a survey in CCT
|
Scott W. |
this all works right now
|
Scott W. |
but what if the server can't give the url because I don't have the right auth token or the request times out or something like that?
|
Scott W. |
Does the LiveData type need to be a new class like "Result" that can also have an exception in it?
|
Mark M. |
yes
|
Mark M. |
this API is in Java (with a planned Xamarin consumer) IIRC, right?
|
Scott W. |
right
|
Sep 12 | 9:10 AM |
Mark M. |
in that case, your LiveData either is of some overall Result class that can hold all the states, or it is of some interface with implementations for the possible states
|
Mark M. |
in the former approach, Result would hold the String, the Throwable (for the error), and some indication of which of those this Result represents (e.g., a boolean or enum value)
|
Scott W. |
got it
|
Mark M. |
in the latter approach, Result is in interface with something like ContentResult and ErrorResult implementations, and the consumer uses instanceof to determine which is which
|
Mark M. |
if this were Kotlin, sealed classes is the typical approach
|
Mark M. |
BTW, before I forget: from an API design standpoint, have your API expose LiveData, not MutableLiveData, unless callers can post stuff
|
Mark M. |
the actual object might be a MutableLiveData, but have the method signature return the LiveData supertype
|
Mark M. |
implementation hiding, and all that
|
Scott W. |
yeah that makes sense.
|
Sep 12 | 9:15 AM |
Scott W. |
we already have this Result logic in place. I'll try to refactor that.
|
Scott W. |
ok. I've got a good direction to go in now.
|
Scott W. |
thank you for the help!
|
Mark M. |
you're welcome!
|
Scott W. |
ok I'm off to work. Have a good day.
|
Mark M. |
you too!
|
Scott W. | has left the room |
Sep 12 | 9:30 AM |
Mark M. | turned off guest access |