2016-09-17 8 views
-3

別のアクティビティに文字列を送信する必要があります。このデータを別のアクティビティに送信する方法

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

私はこのコードを使用しますが、間違っています。

Intent intent = new Intent(); 
    intent.putExtra("timespeent", timeSpent); 
+2

は、質問を投稿する前にグーグルを使って、小さな検索をしてください、このようにあなたのコードを変更する必要があります! –

+0

Intentのクラスを次のようにします。 Intent intent = new Intent(currentclass.this、NextClass.class);intent.putExtra( "timespent"、string); startActivity(インテント); –

答えて

0

あなたが

Intent intent = new Intent(); 
    intent.putExtra("timespeent", string); 
+0

なぜですか? 'long'パラメータを持つメソッドもあります:https://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String、long)* Gordon *に必要なものに依存します。 – gus27

関連する問題