0

Through this code I can display the notification in a text message, but I want to save the text message by by sharedpreference until another notification arrives to replace it even if the application is closed

 @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);



}

}

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Possible duplicate of [Android Shared Preferences](https://stackoverflow.com/questions/5734721/android-shared-preferences) – Adinia Apr 04 '18 at 10:47

1 Answers1

0
 @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();  
  }
Nikunj Peerbits
  • 785
  • 4
  • 12