存储应用的全球数据数据、全球

由网友(木偶有泪在流)分享简介:喜什么是通过存储全局对象/实例了应用程序的最佳方法是什么?Hi What is the best way to store global objects/instances through out the application ?推荐答案下面是下面的code,我用它来存储应用程序上下文字符串。Here is...

喜      什么是通过存储全局对象/实例了应用程序的最佳方法是什么?

Hi What is the best way to store global objects/instances through out the application ?

推荐答案

下面是下面的code,我用它来存储应用程序上下文字符串

Here is the following code which I use to store String in 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

在我名为.manifest添加以下code

In .Manifest I add the following code

<application  android:icon="@drawable/icon" android:label="@string/app_name" android:name="GlobalVariable">

在哪里我想设置字符串我用下面的code的值

Where I want to set the value of string I use the following code

GlobalVariable appState = ((GlobalVariable)getApplicationContext());
appState.setState("Testing");

&放大器;在这里我想以检索我使用的数据。

& where I want to Retrive the data I use

GlobalVariable appState = ((GlobalVariable)getApplicationContext());
appState.getState();
阅读全文

相关推荐

最新文章