在 SharedPreferences 中保存 GCM 推送消息

Save GCM Push message in SharedPreferences

我将 GCM 推送通知发送到我的 android 应用程序,当我单击意图时,消息显示在我的 Activity 中。查看消息后,当 Activity 被销毁或杀死时,消息不再显示在我的 activity 中。我想将消息保存在 SharedPreferences 中,以便我可以在恢复 activity 时查看它。我似乎做对了,但是当我关闭并重新启动 activity.

时,消息没有显示
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_health_notifications);
    msgET = (TextView) findViewById(R.id.message);

    String userEntry = msgET.getText().toString();

    SharedPreferences preferences = getSharedPreferences(Config.STORE_KEY, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();

    editor.putString(Config.USER_TIP, userEntry);

    editor.commit();
} 

将消息存储在 onCreate 中是不正确的。此时尚未设置消息。

而是将其存储在 onStop 中并读回 onStart 中的视图。