通过此代码,我可以在短信中显示通知,但是我想通过sharedPreference保存短信,直到另一个通知到达,即使应用程序已关闭,也要替换它
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
String title = getIntent().getStringExtra("title");
String message = getIntent().getStringExtra("message");
setTitle(title);
TextView desc = (TextView) findViewById(R.id.desc1);
desc.setText(message);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
String title = getIntent().getStringExtra("title");
String message = getIntent().getStringExtra("message");
setTitle(title);
TextView desc = (TextView) findViewById(R.id.desc1);
desc.setText(message);
SharedPreferences.Editor editor = getSharedPreferences("PrefName",
MODE_PRIVATE).edit();
editor.putString("message", message);
editor.apply();
}