-3

I need to send a string to another activity.

      long timeSpent = System.currentTimeMillis() - initialTime;
      timeSpent = (long) (timeSpent / 1000.0);
   String string = "Game Over! Time spent " + String.valueOf(timeSpent) + "s";

I use this code, but it is wrong.

   Intent intent = new Intent();
   intent.putExtra("timespeent", timeSpent);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Gordon
  • 1
  • 1
  • 2
    Please, make a small search by using Google before posting a question! – Todor Kostov Sep 17 '16 at 10:58
  • Pass the class in your Intent like this Intent intent= new Intent(currentclass.this, NextClass.class); intent.putExtra("timespent", string); startActivity(intent); – Preetika Kaur Sep 17 '16 at 11:10

1 Answers1

0

You need to change you code like this

Intent intent = new Intent();
   intent.putExtra("timespeent", string);
Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
  • Why? There's a method with a `long` parameter too: https://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String, long) Depends on what *Gordon* needs. – gus27 Sep 17 '16 at 11:01