Android共享的用于创建一次性活动的偏好设置(示例) [英] Android Shared preferences for creating one time activity (example)

查看:56
本文介绍了Android共享的用于创建一次性活动的偏好设置(示例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个活动A,B和C,其中A和B是表单,并且在将表单数据填充并保存到数据库(SQLITE)中之后.我使用的是从A到B,然后从B到C的意图.我想要的是,每次打开应用程序时,我都希望C作为主屏幕,而不再是A和B.

I have three activities A,B and C where A and B are forms and after filling and saving the form data in database(SQLITE). I am using intent from A to B and then B to C.What i want is that every time I open my app I want C as my home screen and not A and B anymore.

我猜想共享首选项可以解决这个问题,但是我找不到一个很好的例子来说明我的出发点.任何帮助将不胜感激.

I guess shared preferences would work for this, but I cannot find a good example to give me a starting place. Any help would be appreciated.

推荐答案

设置首选项中的值:

// MY_PREFS_NAME - a static String variable like: 
//public static final String MY_PREFS_NAME = "MyPrefsFile";
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
 editor.putString("name", "Elena");
 editor.putInt("idName", 12);
 editor.apply();

从偏好设置中检索数据:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
int idName = prefs.getInt("idName", 0); //0 is the default value.

更多信息:

使用共享首选项

共享的首选项

这篇关于Android共享的用于创建一次性活动的偏好设置(示例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆