Passing information between activities and fragments

To pass information between our activities, we will use the Android Bundle. Bundle can contain multiple values of different types. We will illustrate the use of Bundle by extending our code. Open ItemsFragemnt and update it as follows:

    private fun openCreateNote() { 
      val intent = Intent(context, NoteActivity::class.java) 
      val data = Bundle() 
      data.putInt(MODE.EXTRAS_KEY, MODE.CREATE.mode) 
      intent.putExtras(data) 
      startActivityForResult(intent, NOTE_REQUEST) 
    }  private fun openCreateTodo() { val date = Date(System.currentTimeMillis()) val dateFormat = SimpleDateFormat("MMM dd YYYY", Locale.ENGLISH) val timeFormat = SimpleDateFormat("MM:HH", Locale.ENGLISH) val intent = Intent(context, TodoActivity::class.java) ...

Get Mastering Android Development with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.