0

I am new to android application I have a task is that i should pass data from activity A->Activity B and should pass data between Activity B-----------> Activity C Same way I should get data from Activity C-------> Activity A please tell the scenario or send an example for me

3 Answers3

0

Try two options 1). Intent

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("KEY", "VALUE");
startActivity(intent); 

2). Shared Preference if the data is shared between all activities.

Vaibs
  • 1,128
  • 3
  • 16
  • 36
0

Intent is what you needed:

Intent mIntent = new Intent(ActivityA.this, ActivityB.class);
mIntent.putExtra("key", "value");
startActivity(mIntent);

The above code starts ActivityB and sends the data along with it, to ActivityB (from mIntent.putStringExtra("key", "value");)

You can also see the different prototypes of this from here.

On the next activity, ActivityB, you can get the data sent by code below (write it inside onCreate() in ActivityB):

Intent mIntent = getIntent();
String data_recieved = mIntent.getStringExtra("key"); \\ here key is same as mentioned in previous activity from where you reached here.
Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
0

You can pass data from A to B by using intent:

Intent intent = new Intent(this, Activity.class);
intent.putExtra("name", "value");
startActivity(intent);

You can return back value using onActivtyResult() or by storing it in

shared preferences

If you are using onActivtyResult() method you need to start activty for result using : startActivityForResult() method

You can check this for sending data back send data back to activity

Community
  • 1
  • 1
Sandeep
  • 1,814
  • 21
  • 25