gpt4 book ai didi

android - onPause() : SuperNotCalledException even if super. onPause() 在那里

转载 作者:行者123 更新时间:2023-11-29 14:54:26 25 4
gpt4 key购买 nike

我正在尝试使用 developer.android.com SharedPreferences 中的代码测试 SharedPreferences .我试着稍微改变一下,因为他们说 onStop "may never be called" .问题是 onPause 给我这个奇怪的错误,即使覆盖的第一行是 super.onPause()。

03-09 14:41:00.883: E/AndroidRuntime(394): android.app.SuperNotCalledException: Activity {com.mobinoob.saveinfo/com.mobinoob.saveinfo.SaveInfoActivity} did not call through to super.onPause()

代码示例如下:

public class SaveInfoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListener();
loadText();
textSaved = "";
created = true;
}

private boolean created = false;

private void addListener() {
EditText et = (EditText) findViewById(R.id.editText1);
et.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
textSaved = s.toString();
System.out.println("text:" + textSaved);
}

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}

public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});

}

private static String fileName = "savedInfo.txt";
private static String propertyName = "text";
private String textSaved;

@Override
protected void onPause() {}{
super.onPause();
if (created) {
saveText();
}
}
private void loadText() {
SharedPreferences settings = getSharedPreferences(fileName, MODE_PRIVATE);
if (settings == null)
return;
String result = settings.getString(propertyName, "");
setText(result);
}

private void saveText() {
System.out.println("saving");
SharedPreferences settings = getSharedPreferences(fileName, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString(propertyName, textSaved);
editor.commit();

}
private void setText(String result) {
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(result);
System.out.println("restore" + result);
}

知道我遗漏了什么吗?另请注意所需的 if(created),因为在我第一次启动应用程序时也会调用 onPause()。

最佳答案

protected void onPause() {}{ 

你在那里有一对额外的花括号,使它看起来像一个空函数。

关于android - onPause() : SuperNotCalledException even if super. onPause() 在那里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9635372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com