How do you send data from one activity to another using intents.
(Note this is a two-part question, the sending and the receiving).
I'm creating a form, and I want to save the answers to every question in an sqlite database.
How do you send data from one activity to another using intents.
(Note this is a two-part question, the sending and the receiving).
I'm creating a form, and I want to save the answers to every question in an sqlite database.
Sending (Activity 1):
Intent intent = new Intent(MyCurentActivity.this, SecondActivity.class);
intent.putExtra("key", "enter value here");
startActivity(intent);
Receiving (Activity 2):
String text = getIntent().getStringExtra("key");
You can pass data easily using Bundle.
Bundle b=new Bundle();
b.putString("key", value);
Intent intent=new Intent(TopicListController.this,UnitConverter.class);
intent.putExtras(b);
startActivity(intent);
You can recieve data in your other activity like this as follow:
Bundle b=this.getIntent().getExtras();
String s=b.getString("select");
To send from the Activity
Intent myIntent = new Intent(First.this, Second.class);
myIntent.putExtra("name","My name is");
startActivity(myIntent);
To retrieve in the secod
Bundle bundle = getIntent().getExtras();
String name=bundle.getString("name");
Intent i = new Intent(yourActivity.this, nextActvity.class);
i.putExtra("dataName", data);
//recieving
Intent i = nextActivity.this.getIntent();
string s = i.getStringExtra("dataName", defaultValue);
To pass the data using intent from the current activity use the following code
Intent in = new Intent(YourClassContext, nextActivity.class);
in.putExtra("name","value");
startActivity(in);
To get the intent data passed in the next activity use the following code
Intent i = nextActivity.this.getIntent();
String intentDatapassed = i.getStringExtra("name", defaultValue);