Sid*_*qui 28
以下是我用于存储String在Application Context中的代码.
我上课了 GlobalVariable.java
import android.app.Application;
public class GlobalVariable extends Application
{
private String myState;
public String getState()
{
return myState;
}//End method
public void setState(String s)
{
myState = s;
}//End method
}//End Class
Run Code Online (Sandbox Code Playgroud)
在.Manifest中我添加以下代码
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="GlobalVariable">
Run Code Online (Sandbox Code Playgroud)
我想在哪里设置字符串的值我使用以下代码
GlobalVariable appState = ((GlobalVariable)getApplicationContext());
appState.setState("Testing");
Run Code Online (Sandbox Code Playgroud)
我想在哪里收集我使用的数据
GlobalVariable appState = ((GlobalVariable)getApplicationContext());
appState.getState();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15847 次 |
| 最近记录: |