Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 完全按左键输入应用程序_Java_Android - Fatal编程技术网

Java 完全按左键输入应用程序

Java 完全按左键输入应用程序,java,android,Java,Android,我知道这个问题肯定有很多答案,但不是我找不到,就是我不明白 问题: 我如何让我的应用程序准确启动? F.e.动态添加的复选框不应消失 您可以将这些值存储在SharedReference中 它使用关键值方法进行保存。因此,您可以保存一些值,并随时从SharedReferences读取这些值 这是小数据的最佳方法,可用于应用程序发布。因此,您可以退出应用程序,并且数据仍然存在,以便在下次应用程序启动时读取。您可以将这些值存储在SharedReferences中 它使用关键值方法进行保存。因此,您

我知道这个问题肯定有很多答案,但不是我找不到,就是我不明白

问题:

我如何让我的应用程序准确启动?
F.e.动态添加的复选框不应消失

您可以将这些值存储在SharedReference中

它使用关键值方法进行保存。因此,您可以保存一些值,并随时从SharedReferences读取这些值


这是小数据的最佳方法,可用于应用程序发布。因此,您可以退出应用程序,并且数据仍然存在,以便在下次应用程序启动时读取。

您可以将这些值存储在SharedReferences中

它使用关键值方法进行保存。因此,您可以保存一些值,并随时从SharedReferences读取这些值


这是小数据的最佳方法,可用于应用程序发布。因此,您可以退出应用程序,并且数据仍然存在-以便在下一次应用程序启动时读取。

或将程序的条件保存到文本文件中,以便程序可以在停止之前将其“翻译”回条件,或我不推荐的内容,它会保存使用ObjectOutputStream创建的每个对象。

或者将程序的条件保存到文本文件中,以便程序可以在停止之前将其“翻译”回条件,或者我不推荐的是,它会保存使用ObjectOutputStream创建的每个对象。

没有现成的方法。您可以通过某种方式保存活动的当前状态()

然后,您需要能够在活动生命周期中重建持久化状态的所需状态

您可以使用共享首选项进行保存和加载,例如:

public void saveState(YourState state) {
    SharedPreferences sharedPreferences = app.getSharedPreferences(R.string.preference_file_key, Context.MODE_PRIVATE)
    sharedPreferences.edit()
        .putString("CustomAtt", state.getCustomAtt())
}

public YourState loadState() {
    SharedPreferences sharedPreferences = app.getSharedPreferences(R.string.preference_file_key, Context.MODE_PRIVATE)
    String customAtt = sharedPreferences.getString("CustomAtt", "DefaultValue")
    return new YoutState(customAtt)
}
像这样使用它

@Override
protected void onCreate(Bundle savedInstanceState) {
    YourState state = loadState();
    // Rebuild your activity based on state
    someView.setText(state.getCustomAtt())
}
没有“开箱即用”的方法。您可以通过某种方式保存活动的当前状态()

然后,您需要能够在活动生命周期中重建持久化状态的所需状态

您可以使用共享首选项进行保存和加载,例如:

public void saveState(YourState state) {
    SharedPreferences sharedPreferences = app.getSharedPreferences(R.string.preference_file_key, Context.MODE_PRIVATE)
    sharedPreferences.edit()
        .putString("CustomAtt", state.getCustomAtt())
}

public YourState loadState() {
    SharedPreferences sharedPreferences = app.getSharedPreferences(R.string.preference_file_key, Context.MODE_PRIVATE)
    String customAtt = sharedPreferences.getString("CustomAtt", "DefaultValue")
    return new YoutState(customAtt)
}
像这样使用它

@Override
protected void onCreate(Bundle savedInstanceState) {
    YourState state = loadState();
    // Rebuild your activity based on state
    someView.setText(state.getCustomAtt())
}

保存您的数据。需要时(例如,
onCreate()
)根据保存的数据构建UI。如何保护它D共享首选项?保存数据。需要时(例如,
onCreate()
)根据保存的数据构建UI。如何保护它D共享偏好?