Your Second Kotlin Android App - Part 23: Returning | Ray Wenderlich

Activities not only present layouts to the user, but they can also provide data to other activities.

This is a companion discussion topic for the original entry at

Hey man, quick question. if the user switches between apps or even closes the app in Detail view how can we save the data? is there a preferred way of doing it like override fun onBackPressed() { in Android, is it won’t be called. thank you!

Hi cem. Normally you would do this in the Activity lifecycle onPause() method, and retrieve it in onResume().

hey shouldn’t it be data?.let {
lines 98 and 99

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

How’s so? Would you mind clarifying your question?

Hey, I was wondering about smart casting because sometimes it doesn’t work (not in that case). This is why I thought it would require ‘it’ or for example {data →
I sometimes get Smart cast to xxx is impossible because ‘x’ is mutable property…

Hi standinga, thanks for the clarification! Not sure if I have the entire context of the question, but yes, using let when the nullable is mutable is the way to go.

data?.let {

This is equivalent to putting the nullable into a val and then doing a null check that does a smart cast:

val dataValue = data
if (dataValue != null) {

I hope that answers your question. Let us know if not. Thanks!

Yes my confusion when asking question was about mutable nullable vs non-mutable (where smart cast is possible). It’s all clear now. BTW. Awesome course!!!

Thanks Joe! I appreciate the response. Cheers!

Hi, this was a great tutorial!
In the onActivityResult function in the main activity, you update the recycler view by creating a new recycler view adapter and passing to it the list read from the data manager. Isn’t this a very time consuming task? Because in the the first recycler view might have a long list of items and when we update one of the items, we re-read the whole list from the systems preferences. Wouldn’t it be better to just update the specific item in the list contained in the recycler view adapter? I hope I was clear with my question. Thank you!

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]