-1

How to pass data from one activity to another.

  • Your Android application performs HTTP posts to itself? – David Oct 28 '13 at 13:12
  • Guys I am not looking to pass same data from one activity to other I want to submit a form with dynamic fields,number of fields will be unknown so I asked is there something equivalent to $_POST in php where on submit I can access its elements – androidBeckhamania Oct 28 '13 at 13:22

3 Answers3

2

You can use Intent to pass values from one Activity to another:

First Activity that calls the other:

Intent i = new Intent(this, Activity.class);
i.putExtra("SomeIdentifierName", myClassObj);
startActivity(i);

The called Activity gets the data via:

Intent i = getIntent();
MyClass myClassObj = (MyClass)i.getSerializableExtra("SomeIdentifierName");
jAC
  • 5,195
  • 6
  • 40
  • 55
1

You can e.g. use SharedPreferences or extend Application class. Read more in this article - How to share same data between multiple activities in android?

Community
  • 1
  • 1
TN888
  • 7,659
  • 9
  • 48
  • 84
0

To obtain shared preferences, use the following method In your activity:

SharedPreferences sp= this.getSharedPreferences("LOGINSTATUS", Context.MODE_PRIVATE);

SharedPreferences.Editor editor = sp.edit();
editor.putInt("counter", ++counter);
editor.commit();

The value for counter will get

SharedPreferences sp= context.getSharedPreferences("LOGINSTATUS", Context.MODE_PRIVATE);

//-------get a value from them

String counter = sp.getString("counter", -1);
Nitin Karale
  • 789
  • 3
  • 12
  • 34