一、利用Intent对象携带简单数据
发送:
Intent i = new Intent(this, TwoActivity.class);
//可以装很多数据类型
i.putExtra("type","sss");
startActivity(i);
接收:
String type = getIntent().getStringExtra("type");
二、利用Intent对象携带Bundle
发送:
Intent i = new Intent(this, TwoActivity.class);
Bundle bundle = new Bundle();
//可以装很多数据类型
bundle.putString("type","sss");
i.putExtras(bundle);
startActivity(i);
接收:
Bundle bundle = getIntent().getExtras();
String type = bundle.getString("type");
三、通过Serializable接口或者Parcelable接口
将数据序列化之后,再使用intent、bundle传递都可以
四、全局变量
全局变量需要在同一个进程中,不可以跨进程
五、通过 SharedPreferences 或者MMKV
SharedPreferences不可以跨进程,MMKV可以
六、通过数据库传递
七、通过文件差地
八、Contentprovider
Contentprovider一般用于跨进程