Android Intent数据传递方法

Android系统中,通过Intent传递数据是非常常见的方法。Intent是一种消息传递机制,可以在应用的不同组件之间传递数据。以下是如何使用Intent在Android中传递数据的基本步骤:

  1. 创建Intent对象:
Intent intent = new Intent(this, TargetActivity.class);
  1. 添加数据到Intent:
intent.putExtra("key", "value");
  1. 启动目标Activity并传递数据:
startActivity(intent);
  1. 在目标Activity中获取数据:
String value = getIntent().getStringExtra("key");

通过以上步骤,即可在Android中使用Intent在不同的Activity之间传递数据。

rtf 文件大小:43.45KB