0
点赞
收藏
分享

微信扫一扫

保存全局变量在appliation不管activty的转换

小布_cvg 2023-06-21 阅读 63

public class MyApplication extends Application { 
 
    private String someVariable; 
 
    public String getSomeVariable() { 
        return someVariable; 
    } 
 
    public void setSomeVariable(String someVariable) { 
        this.someVariable = someVariable; 
    } 
} 
<application android:name="MyApplication" android:icon="@drawable/icon" android:label="@string/app_name"> 
// set 
((MyApplication) this.getApplication()).setSomeVariable("foo"); 
 
// get 
String s = ((MyApplication) this.getApplication()).getSomeVariable();

举报

相关推荐

0 条评论