how pass data between more than 2 activities Kotlin

pass data from one activity to another kotlin
kotlin pass object to activity
how to access variables from one activity to another in android
passing data between activities android tutorial
pass data intent in kotlin
intent pass data to another activity kotlin
kotlin pass data from activity to activity
how to pass data using intent in kotlin

I need to pass multiple variables between more than two activities.

I know how to pass between one to another, but not from the first to the third.

Activity One

btnNext.setOnClickListener {
  val i = Intent(this, Activity2::class.java)
  val variableOne= txtVariableOne.text.toString()
  i.putExtra("VARIABLEONE",variableOne)
  startActivity(i)
}

Activity TWO

btnNext.setOnClickListener {
  val i = Intent(this, Activity3::class.java)
  val VariableTwo = txtVariableTwo.text.toString()
  i.putExtra("VARIABLETWO",variableTwo)
  startActivity(i)
}

Activity THREE (This is what I need)

Log.d("DEBUG ", "Value: " + intent.getStringExtra("VARIABLEONE"))
Log.d("DEBUG ", "Value: " + intent.getStringExtra("VARIABLETWO"))

I need access VariableOne and VariableTwo from activity Three.

Thank

Activity TWO

btnNext.setOnClickListener {
  val i = Intent(this, Activity3::class.java)
  val VariableTwo = txtVariableTwo.text.toString()

  //THIS WHAT YOU NEED:
  i.putExtra("VARIABLEONE",intent.getStringExtra("VARIABLEONE"));

  i.putExtra("VARIABLETWO",variableTwo)
  startActivity(i)
}

Simplifying Passing Data Between Activities in Android with Kotlin , If your application has more than just few screens you can find yourself writing a lot of boilerplate code for starting Activities. With help of Kotlin� In this Android Application Development with Kotlin video we will learn about Passing Data Between Activities. For more visit: https://www.simplifiedcoding.net Don't forget to follow us on

Activity Two

 override fun viewAllNotes() {
    val intent : Intent = Intent(this, ViewAllNotesActivity::class.java)
     intent .putExtra("VARIABLEONE",variableOne)
    startActivityForResult(intent, VIEW_ALL_REQUEST_CODE)
  }


  override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
 super.onActivityResult(requestCode, resultCode, data)
 if (resultCode == Activity.RESULT_OK){
    if (requestCode == VIEW_ALL_REQUEST_CODE){
  //get data here
        }
    }
    }
 }

Activity three

@Override
public void onBackPressed() {
    Intent result = new Intent();
    result .putExtra("VARIABLEONE",variableOne)        
    setResult(Activity.RESULT_OK, result);
    this.finish();
  }

Or else you can store the values using Shared-preference and get values any where in the project

Passing data between Activities. Communicating with Objects and , 2. Using Intents. Intents are the most generally accepted way of passing primitive data and Strings between Activities. They offer more flexibility� The important announcement by google in 2017 for android developers is that kotlin is now an official language for android app development. for more on introduction and basic you can visit previous blog "getting started with kotlin for android app development - an introduction and basics".coming to the topic, today in this tutorial, i will guide you about how we can navigate/switch

I can say the same as we passing in java There are many ways From the one is, You can pass by intent when starting another activity which is proper when you think data at the time of starting the activity like bellow,

val intent = Intent(mActivity, LoginActivity::class.java);
intent.putExtra("keyName", data)
startActivity(intent)

Another way you can use preference or store data in preference and you can use where ever you need.

Android Kotlin YouTube: Pass Data Between Activity through Intent , Android Kotlin YouTube: Pass Data Between Activity through Intent (Ep 5) In today's lesson Duration: 20:07 Posted: Dec 28, 2017 Kotlin Android - Start Another Activity - Example : To start new (another) Android Activity from an Activity : In the current Activity, create an Intent with current activity's context and Next Activity Class passed as arguments. val intent=Intent(this, AnotherActivity::class.java) Call startActivity() method with intent passed as argument.

Pass Data between Activities using intent (Kotlin), Pass Data between Activities using intent (Kotlin) - Android Studio Tutorial Activity 2: Show Duration: 14:18 Posted: Mar 21, 2018 Passing Data Between Activity Overview. This example contains two activity, source activity and target activity. There are two button in source activity and one button in target activity. Click the first button will transfer data to target activity.

#2.4 Kotlin Android Tutorial: Share Data between Activities using , Learn how to use Explicit Intent to pass data from one Activity to another https:// bit.ly Duration: 10:03 Posted: May 27, 2018 You can use Intents to pass data between activities. While starting another use putExtra method of the intent. eg: [code]Intent i = new Intent(FirstActivity.this, SecondActivity.class); i.putExtra("EXTRA_KEY_1", "value1"); i.putExtra("EXTRA_KEY_2"

Passing data between Activities using Intent in Android, Through Intent we can move from one activity to another activity and Intent… then we will pass the data using Intent from one activity to another. Step 2 : Whats Next ??? Now we have to create a new activity so let's More From Medium Android Networking in 2019 — Retrofit with Kotlin's Coroutines. Passing Intent extras is a good approach as Erich noted.. The Application object is another way though, and it is sometimes easier when dealing with the same state across multiple activities (as opposed to having to get/put it everywhere), or objects more complex than primitives and Strings.

Comments
  • Passing data from activity to another, I think is a simple task that someone will answer below. But what I would suggest is to figure out if you can actually perform that same task in single activity using Fragments? Because what you are currently doing is highly inefficient in terms of performance as well as maintainability.
  • Thx, i try shared preference and its the best solution.