Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from other activity in android?

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 TextViews 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?

like image 677
Vignesh Avatar asked Jan 25 '11 11:01

Vignesh


People also ask

How can use data from another activity in Android?

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.

How do I pass data from another activity?

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.

How do you pass data between two activities through intent?

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.

How do you send data from first activity to third activity?

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.


1 Answers

you have a typo:

bundle.putString("vidoedetails", filedetails);

should be

bundle.putString("videodetails", filedetails);
like image 144
dave.c Avatar answered Sep 29 '22 01:09

dave.c