O'Reilly logo

Mastering Android Development with Kotlin by Miloš Vasić

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required