I have two activities such as Activity
A and B and I'm trying to pass two different strings from A to B using Bundle
and startActivity(intent)
.
Like that:
Intent intent = new Intent(A.this, B.class);
Bundle bundle = new Bundle();
bundle.putString("vidoedetails", filedetails);
//bundle.putString("videoname", filename);
intent.putExtras(bundle);
//intent.putExtra("videofilename", filename);
//intent.putExtra("vidoefiledetails", filedetails);
startActivity(intent);
And in class B I'm using two TextView
s to display the strings from class A seperately.
Like that:
Intent i = getIntent();
Bundle extras = i.getExtras();
filedetails = extras.getString("videodetails");
filename = extras.getString("videoname");
The problem is filedetils
get printed in class B but not the file name.
Any solution for this?
In your second activity, you can get the data from the first activity with the method getIntent() and then getStringExtra() , getIntExtra() ... Then to return to your first activity you have to use the setResult() method with the intent data to return back as parameter.
Using Intents This example demonstrate about How to send data from one activity to another in Android using intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
To pass data between two activities, you will need to use the Intent class via which you are starting the Activity and just before startActivity for ActivityB, you can populate it with data via the Extra objects. In your case, it will be the content of the editText.
You can pass the value in 2 ways: Either you make a global Class and set the value in that class and access that class in your 3rd activity. You can use Intent to send your values from 1st activity to 2nd activity.
you have a typo:
bundle.putString("vidoedetails", filedetails);
should be
bundle.putString("videodetails", filedetails);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With