作者:手机用户2502939381 | 来源:互联网 | 2023-09-18 20:51
Ihavemadeasharedpreferenceactivitythatstoretheusersettings,nowiwanttogetvaluesina
I have made a shared preference activity that store the user settings, now i want to get values in a activity or normal java class.please provide a solution or example i have already tried this code but failed.
我已经创建了一个存储用户设置的共享首选项活动,现在我想获取活动或普通java类中的值。请提供一个解决方案或示例我已经尝试过此代码但失败了。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
SharedPreferences channel=this.getSharedPreferences(strFile, Context.MODE_PRIVATE);
strChannel=channel.getString(keyChannel,"Default").toString();
Toast.makeText(getApplicationContext(), strChannel, Toast.LENGTH_LONG).show();
}
in this code strfile
for eg. com.android.pack.ClassName
is SharedPreference Activity
from values to be fetched, and keyChannel is key that is same in SharedPreference Activity
.
在这个代码strfile中,例如。 com.android.pack.ClassName是来自要提取的值的SharedPreference Activity,而keyChannel是SharedPreference Activity中相同的键。
Kindly provide the solution.
请提供解决方案。
4 个解决方案