Activity 值的传递:
1、(MainActivity.java代码:意图传递值)
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("name", "jack");
intent.putExtra("age", 23);
intent.putExtra("address", "北京");
Bundle bundle = new Bundle();
bundle.putString("code", "1001");
intent.putExtra("bundle", bundle);
StartActivity(intent);
(NextActivity.java代码:提取数据)
<pre name="code" class="html">Intent intent = getIntent(); // getIntent()是将项目中包含的原始intent检索出来;整句是将检索出来的intent赋值给一个Intent类型的变量intent
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 0);
String address = intent.getStringExtra("address");
Bundle bundle =intent.getBundleExtra("bundle");
String code = bundle.getString("code");
2、 调试程序
<pre name="code" class="html">...
private final TAG = "NextActivity";
...
Intent intent = getIntent(); // getIntent()是将项目中包含的原始intent检索出来;整句是将检索出来的intent赋值给一个Intent类型的变量intent
String name = intent.getStringExtra("name");
Log.i(TAG, "-->>" + name); // 前面表示要过滤的目标标签
int age = intent.getIntExtra("age", 0);
Log.i(TAG, "-->>" + age);
String address = intent.getStringExtra("address");
Log.i(TAG, "-->>" + address);
Bundle bundle =intent.getBundleExtra("bundle");
String code = bundle.getString("code");
Log.i(TAG, "-->>" + code);
在LogCat(deprecated)的Filter框输入"--"进行过滤查看。
点击"+"(CreateFilter),
filter name : NextActivity
by log tag: NextActivity
by log level: Info