1
Hello, I’m starting to work with Kotlin and I have the following situation:
- I have the Activity Foo with a button that navigates to Activity Bar.
- In Bar, I process some information and have a button to go back.
- When returning, I must return this processed information to Foo
I wonder if there is already some standard implemented to do this in Kotlin (Android) so I can learn already using best practices...
Note: at first I thought of having a Viewmodel implanted in Foo and try to pass on to Bar the instance of the same, but it seemed to me a little bit "forced" so I came to clarify better the "how to do"
The "canonical" way would be to use Intents, personally I prefer to use Sharedpreferences, activity B modifies a value in the application’s Shared preferences, and activity A is the Preference Change System. The use of a shared Singleton among the various activities, perhaps residing in a static class, is also valid.
– epx
I would say that the title of the question is not very clear, because it gives the idea of inheritance between the Activities, when in the example
Foo
andBar
are distinct and do not share any relationship of inheritance– Isac
So I think if I take and use a VM that can be passed to the second is valid because it would work as a correct Singleton?
– LeandroLuk