


MainActivity.kt is our first activity name and activity_main.xml is its layout file. The second activity will read the data and show it in a TextView. On click, we will start the second Activity and pass the string that was entered in the EditText. The user will enter text in the EditText and click on the button. In this example, we will create one Application with two screens or Activities: the first Activity will hold one EditText and one Button. Optionally, we can set data to an intent.

The intent object takes the start activity and destination activity names. We can use one intent to pass data from one Activity to another Activity, starting service or delivering broadcasts. For passing data in Android, we need to use objects of class Intent. We will use Kotlin and Android Studio in this exercise. Although, in those cases, we get an exception instead of the incorrect Enum value.In this example, we will learn how to pass data from one Activity to another in Android. It's important to note that other solutions, like using the name instead of the position, will also fail if we rename any of the values. However, for the rest of the time, it should be ok. This can be an issue with things like Intents inside pending intents as they may survive updates. One of the downsides is that, if we change the order of the Emums, then any old reference will not work. The IDE will autocomplete these functions which means there is no need to have previous knowledge of the utility class.The functions are more familiar as they are similar to the SDK ones.We don't require the "overhead" of an intermediary object to do the serialization as it's all done in place thanks to inline which will replace the calls with the code inside the function.There are a few benefits of doing it this way. This is an old question, but everybody fails to mention that Enums are actually Serializable and therefore can perfectly be added to an Intent as an extra.
