Activity間ジャンプ
2295 ワード
データの転送
/**
* activity
*
* @param v
*/
public void click4(View v) {
// intent-filter
Intent intent = new Intent();
intent.setAction("com.example.activeswitch.second");
intent.setDataAndType(Uri.parse("hello:123"), "text/username");
startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent intent = getIntent();
Uri uri = intent.getData(); // hello:123
String type = intent.getType(); // text/username
}
// Activity
public void click7(View v) {
Intent intent = new Intent();
intent.setAction("com.example.activeswitch.second");
//
intent.putExtra("username", "hello world");
intent.putExtra("password", "android");
//
Bundle bundle = new Bundle();
bundle.putString("username", "hello android");
bundle.putString("password", "123");
intent.putExtras(bundle);
startActivity(intent);
}
// Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent intent = getIntent();
//
/*String username = intent.getStringExtra("username");
String password = intent.getStringExtra("password");*/
//
Bundle bundle = intent.getExtras();
String username = bundle.getString("username");
String password = bundle.getString("password");
System.out.println("username:" + username + " password:" + password);
}