1创建一个包,命名Bean
2.声明两个对象,然后将光标放置我们所要生成get,set方法的对象处,然后右击,选择Genera 选择“Getter and Setter ”,然后“OK”即可 这就生成get set 方法了
Code—>Genera —> Getter and Setter
package com.example.demo.Bean; public class Data extends { private String ed_dbuser; private String ed_dbpassword; public String getEd_dbuser() { return ed_dbuser; } public void setEd_dbuser(String ed_dbuser) { this.ed_dbuser = ed_dbuser; } public String getEd_dbpassword() { return ed_dbpassword; } public void setEd_dbpassword(String ed_dbpassword) { this.ed_dbpassword = ed_dbpassword; } }
注意 在一个activity里 new 的实例方法 只能在当前这个activity里调用
Data data =new Data();
data.setEd_dbname();
data.getEd_dbname()
参考: https://blog.csdn.net/qq_38041708/article/details/80544881
如果其他activity 需要公用这对象需要设置全句变量
Application的定义继承关系如下:
Object <- Context <- ContextWrapper <- Application <- BaseApplication
package com.example.demo.Bean; import android.app.Application; public class Data extends Application { private String ed_dbuser; private String ed_dbpassword; public String getEd_dbuser() { return ed_dbuser; } public void setEd_dbuser(String ed_dbuser) { this.ed_dbuser = ed_dbuser; } public String getEd_dbpassword() { return ed_dbpassword; } public void setEd_dbpassword(String ed_dbpassword) { this.ed_dbpassword = ed_dbpassword; } }
继承Application 后所有的activity 都可以访问 Data里的对象
Data data=(data) getApplication();
在清单文件还要配置
android:name="com.example.demo.Bean.Data">