Office Hours — Today, September 12

Tuesday, September 10

Sep 12
8:20 AM
Mark M.
has entered the room
8:25 AM
Mark M.
turned on guest access
8:55 AM
Scott W.
has entered the room
Scott W.
Hello!
Mark M.
hi! sorry for the delay!
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.
Activity A needs to kick off a chrome custom tab(CCT). When the CCT is closed, my app should return to Activity B.
Or, Activity A should know that the CCT ended and finish itself
Activity B is decided by a TaskStackBuilder that was created earlier.
9:00 AM
Mark M.
I don't know exactly what "ended" or "closed" means with respect to the CCT
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
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
all right I'll go with this solution.
I have one more question about LiveData
Mark M.
I know a lot more about LiveData than CCT, so that's promising! :-)
9:05 AM
Scott W.
I'm working on this SDK design, and trying to avoid exposing our custom Deferred objects.
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
actually
app layer will call getCallSurvey(int callId)
normally, this method would return a Deferred object
I've implemented it to return a MutableLiveData object
a ViewModel object makes the call
and an Activity registers itself as an observer through the ViewModel.
the actual data is a String directing the user to a survey in CCT
this all works right now
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?
Does the LiveData type need to be a new class like "Result" that can also have an exception in it?
Mark M.
yes
this API is in Java (with a planned Xamarin consumer) IIRC, right?
Scott W.
right
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
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
if this were Kotlin, sealed classes is the typical approach
BTW, before I forget: from an API design standpoint, have your API expose LiveData, not MutableLiveData, unless callers can post stuff
the actual object might be a MutableLiveData, but have the method signature return the LiveData supertype
implementation hiding, and all that
Scott W.
yeah that makes sense.
9:15 AM
Scott W.
we already have this Result logic in place. I'll try to refactor that.
ok. I've got a good direction to go in now.
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
9:30 AM
Mark M.
turned off guest access

Tuesday, September 10

 

Office Hours

People in this transcript

  • Mark Murphy
  • Scott Wehby