2016-07-28 48 views

回答

0

而且在應用標籤

<application 
    android:name=".YourApplication" 
    android:allowBackup="true" 
    android:hardwareAccelerated="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme"> 

在應用程序的onCreate方法。這是最好的地方。它會在您的應用程序創建時執行。

public class YourApplication extends Application { 

public static Boolean sAppOpened = false; 


@Override 
public void onCreate() { 
    super.onCreate(); 
    //Write your code here 
    sAppOpened = true; 


.... 
} 

... 
} 
0

聲明你的共享偏好設置文件名類範圍的這樣的 -
public static final String SHARED_PREFERENCES = "SHARED_PREF";

您可以在OnCreate方法使用。

SharedPreferences sharedpreferences = getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE); 
Editor editor = sharedpreferences.edit(); 
editor.putString("key", "value"); 
editor.commit(); 
相關問題