0

i make app with 2 activity 1 and 2 and want to share number wrote in text view in page activity 1 direct in calculation in page activity 2 to be viewed in text view in this page 2 (for example if first text view contains number 10 and i want to use this number in second activity in calculation like "value+10" and the result will be viewed in text view in page activity 2) without make any addition field in page 2

Wael Youssef
  • 49
  • 1
  • 10
  • send this number 10 to activity 2 by using Intent – J Ramesh Aug 31 '17 at 13:09
  • Please don't repost. https://stackoverflow.com/questions/45951575/android-studio-code-for-pass-data-between-two-edit-texts-in-different-activitie – OneCricketeer Aug 31 '17 at 13:13
  • I write 10 as example i need the cell contains number to pass to next activity in equation – Wael Youssef Aug 31 '17 at 13:44
  • now i want to use number in one activity field in calculation in activity two field and this different than the last question because i dont want to built another field in activity 2 to recieve that number in activity one(TextView in activity 2 = 3×value 1 in activity 1 )for example – Wael Youssef Aug 31 '17 at 21:49

2 Answers2

0

You could pass it in a Bundle

Intent intent = new Intent(this, OtherActivity.class);
Bundle bundle = new Bundle();

bundle.putInt("something", 1);
intent.putExtras(bundle);
startActivity(intent);

In you OtherActivity:

 Bundle bundle = getIntent().getExtras();
 int something;

 if (bundle != null) {
     something = bundle.getInt("something");
 }else{
     //
 }

This way you can pass a bunch of arguments to the next activity.

Razor
  • 66
  • 12
  • Is there any way than intent..because in intent way i must make cell (like text view) to recieve number in it from activity one and then use ..i only need put number in activity one in equation in activity 2 – Wael Youssef Aug 31 '17 at 14:45
0

Code In Activity1

Intent intent = new Intent(this, Activity2.class);
intent.putExtra("number", 10);
startActivity(intent);

Code In Activity2

int number = getIntent().getIntExtra("number", 0);
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
J Ramesh
  • 548
  • 4
  • 11
  • i want to use number in one activity field in calculation in activity two field . i dont want to built another field in activity 2 to recieve that number in activity one i want this number go directly in equation in activity 2 like this (TextView in activity 2 = 3×value1 in activity 1 )for example – Wael Youssef Aug 31 '17 at 21:53
  • you can directly write (TextView in activity 2 = 3× getIntent().getIntExtra("number", 0) in activity 1 ) otherwise you need to public static variable for accessing value – J Ramesh Sep 01 '17 at 04:36