在webview app关闭暂停之前,要恢复用户的最后一页。但是我在onPause
和onResume
方法中遇到错误,我不知道如何解决错误cannot resolve symbol context | cannot resolve method put
@Override
protected void onPause() {
// cannot resolve symbol context
// cannot resolve method put
super.onPause();
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE);
SharedPreferences.Editor edit = prefs.edit();
edit.put("lastUrl", exfilevbrowser.getUrl());
edit.commit();
}
@Override
protected void onResume() {
super.onResume();
// cannot resolve symbol context
if(exfilevbrowser != null) {
SharedPreferences prefs = context.getApplicationContext().getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE);
String s = prefs.getString("lastUrl","");
if(!s.equals("")) {
appLoadUrl(s, false);
}
}
}
答案 0 :(得分:0)
如果您在某个活动中,请直接使用getSharedPreferences()
代替context.getApplicationContext().getSharedPreferences()
如果您在片段内,请使用getContext().getSharedPreferences()
然后使用edit.putString()
代替edit.put()