1

Possible Duplicate:
How do I pass data between Activities in Android application?

How would I go about transferring some data between two activities?

my 1st activity takes current time

startTime = System.currentTimeMillis(); 

and my second activity contains a little sum with the startTime

long elapsedTime = System.currentTimeMillis() - startTime;
Cœur
  • 32,421
  • 21
  • 173
  • 232
Leigh8347
  • 91
  • 7

2 Answers2

1

When starting second activity:

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putLong("startTime", System.currentTimeMillis());
intent.putExtras(b);
startActivity(intent);

Reading the value in the second activity:

Bundle b = getIntent().getExtras();
long value = b.getLong("startTime", 0);
Dmitry
  • 15,996
  • 2
  • 37
  • 65
0

You can pass data between activities by using the extras in an Intent object. When you create your intent, simply do a:

myIntent.put("startTime", startTime);

and in your other activity, do a:

intent.getIntExtra("startTime", 0);
Kristopher Micinski
  • 7,410
  • 3
  • 27
  • 33