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

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(); 

你可能感兴趣的:(android)