Passing data from one activity to another using bundle - not displaying in second activity
Two ways you can send the data. This is how you are sending it at the moment. And there is nothing wrong with it.
//Create the bundle
Bundle bundle = new Bundle();
//Add your data from getFactualResults method to bundle
bundle.putString("VENUE_NAME", venueName);
//Add the bundle to the intent
i.putExtras(bundle);
startActivity(i);
In you code (second Activity) however, you are referring to the key
in the Bundle as MainActivity.VENUE_NAME
but nothing in the code suggests that you have a class that returns the value as the actual key
name send with the Bundle. Change your code in the second Activity to this:
Bundle bundle = getIntent().getExtras();
//Extract the data…
String venName = bundle.getString("VENUE_NAME");
//Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(venName);
You can check in your second Activity if the Bundle contains the key using this and you will know that the key
is not present in the Bundle. The correction above, however, will get it working for you.
if (bundle.containsKey(MainActivity.VENUE_NAME)) {
....
}
Why does it not pass data when I pass bundle from one activity to another in android?
Your code is incomprehensible:
1) what are you doing? setContentView(R.layout.datalayout);
2) What is data
in data.getText().toString();
If you see the toast with no text in it that means that dataToInclude
is either null
or empty.
So focus to check data1
and data2
variables.
Edit: When you click on text
the listener is executed immediately:
the new layout is shown with empty EditTexts, their empty strings are stored in data1
and data2
and you open the new activity with empty strings in the bundle.
unable to send values from one activity to other in Android
try this:
public void rsa_key(String s){
Intent intent = new Intent(getBaseContext(), SomeClass.class);
//String hello=null;
intent.putExtras("id", txId);
intent.putExtras("cardamt", cardAmount);
intent.putExtras("cardconv", cardConvFee);
startActivity(intent);
}
in your second activity onCreate method
Bundle bundle = getIntent().getExtras();
String txId = bundle.getString("id");
String cardConvFee = bundle.getString("cardconv");
String cardAmount = bundle.getString("cardamt");
getting error when passing data from one activity to another activity
You made mistake here
startActivity(intent);
You put intent value in intent and start activity is intent1. So please pass intent1
instead of intent
startActivity(intent1);// pass this intent1
Use this code
Intent intent1 = new Intent(Name.this, Signup.class);
intent1.putExtra("userId", userId);
intent1.putExtra("token",token);
startActivity(intent1);
Log.e(TAG, "token: " + token);
Log.e(TAG, "userId: " + userId);
Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();
startActivity(intent1);
Android send data from activity to activity using bundle
in SendAnswerToServer Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getIntent().getExtras();
if(bundle !=null)
{
//ObtainBundleData in the object
String strdata = bundle.getString("time");
//Do something here if data received
}
else
{
//Do something here if data not received
}
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").
Related Topics
How to Get All Android Contacts But Without Those Which Are on Sim
Call Method When Home Button Pressed
Programmatically Change the Value of a Color Resource Obtained from API Response
How to Set Internet Options for Android Emulator
Removing Log Call Using Proguard
Reading Text File from Server on Android
Asynctask and Looper.Prepare() Error
Comparing Two Drawables in Android
What Does It Mean "No Launcher Activity Found!"
Android - Set Text to Textview
Android - Nullpointerexception on Searchview in Action Bar
Android Studio Error Installing Gradle
Scan_Results_Available_Action Return Empty List in Android 6.0
How to Use Custom Font with Webview
Broadcastreceiver When Wifi or 3G Network State Changed
How to Integrate Opencv Manager in Android App