How do I pass data between Activities in Android application?
The easiest way to do this would be to pass the session id to the signout activity in the Intent
you're using to start the activity:
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent);
Access that intent on the next activity:
String sessionId = getIntent().getStringExtra("EXTRA_SESSION_ID");
The docs for Intents has more information (look at the section titled "Extras").
How to send string from one activity to another?
You can use intents, which are messages sent between activities. In a intent you can put all sort of data, String, int, etc.
In your case, in activity2
, before going to activity1
, you will store a String message this way :
Intent intent = new Intent(activity2.this, activity1.class);
intent.putExtra("message", message);
startActivity(intent);
In activity1
, in onCreate()
, you can get the String
message by retrieving a Bundle
(which contains all the messages sent by the calling activity) and call getString()
on it :
Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");
Then you can set the text in the TextView
:
TextView txtView = (TextView) findViewById(R.id.your_resource_textview);
txtView.setText(message);
How do I transfer data from one activity to another in Android Studio?
Inside Activity2
You can place data inside the Intent
directly or you can put them in a Bundle
and then put the inside the Intent
. Avoid using both for consistency.
Intent activity3Intent = new Intent(getApplicationContext(), Activity3.class);
//Direct Intent approach
activity3Intent.putExtras("YOUR_STRING_KEY","YOUR_DATA");
//OR Bundle approach
Bundle bundle = new Bundle();
bundle.putString("YOUR_STRING_KEY","YOUR_DATA");
activity3Intent.putExtras(bundle);
startActivity(activity3Intent);
Inside the Activity3
class.
//if direct intent approach
String value = getIntent.getStringExtra("YOUR_STRING_KEY")
//If bundle approach was used.
String value = getIntent().getExtras().getString("YOUR_STRING_KEY");
Pass Intent from one activity to another activity
Here's the solution, thanks to @YodaScholtz for the hint.
I wrote the following code
In MainActivity
Intent intent = new Intent(this, typeof(SecondActivity));
intent.PutExtra("ClipData", intent.ClipData);
StartActivity(intent);
SecondActivity code
if (intent.HasExtra("ClipData"))
{
var _data = intent.Extras;
var _clipdata = (ClipData)_data?.GetParcelable("ClipData");
intent.ClipData = _clipdata;
ProcessIntent(intent);
}
Transfer data from one Activity to Another Activity Using Intents
Through the below code we can send the values between activities
use the below code in parent activity
Intent myintent=new Intent(Info.this, GraphDiag.class).putExtra("<StringName>", value);
startActivity(myintent);
use the below code in child activity
String s= getIntent().getStringExtra(<StringName>);
Using intents to pass data between activities
Pass the data from Activity-1
to AndroidTabRes..
as below:
At sending activity...
Intent intent = new Intent(current.this, AndroidTabRestaurantDescSearchListView.class);
intent.putExtra("keyName","value");
startActivity(intent);
At AndroidTabRes..
activity...
String data = getIntent().getExtras().getString("keyName");
Thus you can have data at receiving activity from sending activity...
And in your AndroidTabRestaurantDescSearchListView
class, do this:
String value= getIntent().getStringExtra("keyName");
Intent intent = new Intent(this, RatingDescriptionSearchActivity.class);
intent.putExtra("keyName", value);
startActivity(intent);
Then in your RatingDescriptionSearchActivity
class, do this:
String data= getIntent().getStringExtra("keyName");
How to pass data from one activity to another activity
Assuming you are saving the events in some model class, what you can do is when calling the onBindViewHolder
method of your adapter, check if the event is marked as save. If it is, then you either need to change the heart image to another heart image which is yellow, or you can apply a tint on the heart image to make it yellow.
You can change drawable by using this code
heartImageView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.yellow_heart));
You can apply tint by using this code
heartImageView.setColorFilter(Color.argb(255, 255, 255, 0))
EDIT (Based on comment)
If the heart is in the first activity and the interested button is in the second activity what you need to do is to save the state of the event when you click on the interested button. Once you go back to the the first activity, you can check the state of the event and then update the image by using any of the above two methods.
EDIT 2 (Based on new code shared)
After you get the response from your Volley call, you should save the event id somewhere to keep track of which events you are interested in (this can be in either a model class or some global list). When you go back to your first activity (which contains the recyclerview), you need to check each event id with the stored event id list that you have and change the heart for each event that matches.
Passing data from one activity to another and then printing
The problem is your intent in your first class
Intent intent = new Intent("com.example.*******.loginpage.User"); <-- have created an intent
intent.putExtra("username",String.valueOf(username));
startActivity(new Intent(MainActivity.this, User.class)); <-- but using new Intent
You have created an intent but you passing new intent. Use your created Intent instead of passing new Intent.
Intent intent = new Intent(MainActivity.this, User.class);
intent.putExtra("username",String.valueOf(username));
startActivity(intent);
EDIT
Instead using String.valueOf(username)
you must use username.getText()
, because String.valueOf(username)
is method to translate your object to String.
Intent intent = new Intent(MainActivity.this, User.class);
intent.putExtra("username",username.getText());
startActivity(intent);
Related Topics
Cli on Dalvikvm Fails on Jni Lib
Youtube Video Not Playing in Webview
Set Language to French in Android Datepickerdialog
Http Post Method Passing Null Values to the Server
Properly Using Asynctask Get()
Differencebetween Sendstickybroadcast and Sendbroadcast in Android
On Showing Dialog I Get "Can Not Perform This Action After Onsaveinstancestate"
Adding Custom Font to Theme in Android
Android Access to Remote SQL Database
How to Break Styled Text into Pages in Android
How to Set Delay in Android Onclick Function
Ask for Password Before Uninstalling Application
How to Solve Nullpointerexception Error in Android