2011-06-16 169 views

回答

1

为此使用SharedPreference。创建一个布尔变量并在操作完成后进行更改。在主/启动器活动的onCreate中检查此变量并相应地执行操作。一些伪代码。

if (!sharedpreferences.getBoolean("isOpComplete", false)) { 
    // perform my operation 
    performOperation(); 
} 

performOperation() { 
    // Operation complete 
    SharedPreferences.Editor editor = sharedpreferences.edit(); 
    editor.putBoolean("isOpComplete", true); 
    editor.commit(); 
} 
+2

我想在第二种方法的末尾需要'commit()'。 – 2011-06-16 15:27:46

3

使用偏好

在活动

private boolean isFirstLaunch() { 
    // Restore preferences 
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
    boolean isFirstLaunch = settings.getBoolean("isFirstLaunch", true); 
    Log.i(TAG + ".isFirstLaunch", "sharedPreferences "); 
    return isFirstLaunch; 
} 

,并从onCreate通话

if (isFirstLaunch()) { 
    Intent firstLaunchIntent = new Intent(this, 
     GetStartedActivity.class); 
    firstLaunchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(firstLaunchIntent); 
    // set the bool to false in next activity ! 
    finish(); 
} 
+0

我在哪里可以做到这一点,它会在我的主要活动课上? – molleman 2011-06-16 15:12:30

+0

@molleman检查编辑 – olamotte 2011-06-16 15:12:52

1

添加标记在你的数据库,共享偏好或文件表示你已经下载了数据。在onResume中,检查该标志以及设备是否具有连接性。如果标志为假并且您有连接性,请尝试下载数据。

如果这样做成功,更新标志。

相关问题