【问题标题】:How the Activities are kept in preference screen settings活动如何保存在首选项屏幕设置中
【发布时间】:2016-08-06 12:00:51
【问题描述】:

如何将活动保存在 listView 首选项中,以便当用户在首选项中选择活动时,当用户下次启动应用程序时,它们将显示为第一个屏幕?

【问题讨论】:

    标签: android android-activity android-preferences


    【解决方案1】:

    当用户选择一个 Activity 来保存它的首选项时,您可以将该 Activity 的名称保存到 sharedPreferences。 然后在您的 MainActivity 类中,当应用再次运行时,检查保存的活动并启动它。

    this SO question

    保存到首选项:

    PreferenceManager.getDefaultSharedPreferences(context).edit().putString("MYACTIVITY", "myStringToSave").commit();
    

    获取存储的偏好:

    PreferenceManager.getDefaultSharedPreferences(context).getString("MYACTIVITY", "defaultStringIfNothingFound"); 
    

    myStringToSave 可以是所选活动的名称

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多