Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在活动之间传输数据_Java_Android - Fatal编程技术网

Java 在活动之间传输数据

Java 在活动之间传输数据,java,android,Java,Android,可能重复: 我如何在两个活动之间传输一些数据 我的第一个活动占用当前时间 startTime = System.currentTimeMillis(); 我的第二个活动包含一个小的开始时间的总和 long elapsedTime = System.currentTimeMillis() - startTime; 您可以通过使用Intent对象中的extra在活动之间传递数据。创建意图时,只需执行以下操作: myIntent.put("startTime", startTime); 在其

可能重复:

我如何在两个活动之间传输一些数据

我的第一个活动占用当前时间

startTime = System.currentTimeMillis(); 
我的第二个活动包含一个小的开始时间的总和

long elapsedTime = System.currentTimeMillis() - startTime;

您可以通过使用Intent对象中的extra在活动之间传递数据。创建意图时,只需执行以下操作:

myIntent.put("startTime", startTime);
在其他活动中,请执行以下操作:

intent.getIntExtra("startTime", 0);

您可以通过使用Intent对象中的extra在活动之间传递数据。创建意图时,只需执行以下操作:

myIntent.put("startTime", startTime);
在其他活动中,请执行以下操作:

intent.getIntExtra("startTime", 0);

开始第二个活动时:

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putLong("startTime", System.currentTimeMillis());
intent.putExtras(b);
startActivity(intent);
Bundle b = getIntent().getExtras();
long value = b.getLong("startTime", 0);
读取第二个活动中的值:

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putLong("startTime", System.currentTimeMillis());
intent.putExtras(b);
startActivity(intent);
Bundle b = getIntent().getExtras();
long value = b.getLong("startTime", 0);

开始第二个活动时:

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putLong("startTime", System.currentTimeMillis());
intent.putExtras(b);
startActivity(intent);
Bundle b = getIntent().getExtras();
long value = b.getLong("startTime", 0);
读取第二个活动中的值:

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putLong("startTime", System.currentTimeMillis());
intent.putExtras(b);
startActivity(intent);
Bundle b = getIntent().getExtras();
long value = b.getLong("startTime", 0);
见问题:见问题: