我想从同一应用程序中的另一个活动访问一个活动中的时间选择器。例如,如果我在一个活动中更改了时间选择器中的时间,则在另一活动中更改了时间选择器中的时间也应相应地进行更改。我怎样才能做到这一点?
您可以使用putExtra将数据传递到新的意图。
int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();
String time = hour + ":" + minute;
Intent intent = new Intent(getBaseContext(), NewActivity.class);
intent.putExtra(time, "timeData");
startActivity(intent)
查看时间。
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("timeData");
//do stuff with the time now...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句