私はアクティビティクラスに値を持っています。私は、その値を非アクティビティクラスで使用したいと思います。通常、アクティビティクラスの間でデータを共有するために、私はAndroidのアクティビティクラスから、非アクティビティクラスへの共有設定を取得するにはどうすればよいですか?
FirstActivityClass.java
SharedPreferences notification_id = getSharedPreferences("NOTIFICATION_ID", MODE_PRIVATE);
SharedPreferences.Editor notificationIDEditor = notification_id.edit();
notificationIDEditor.putString("notification_id", notificationId)
notificationIDEditor.apply();
そして、別のクラスにnotification_idの値を取得するために、のような使用し、
SecondActivityClass.java
SharedPreferences notificationIDSharedRetrieve = getSharedPreferences("NOTIFICATION_ID", MODE_PRIVATE);
notificationID = notificationIDSharedRetrieve .getString("notification_id", null);
しかし、2番目のクラスが非アクティビティクラスのデータを取得するにはどうすればよいですか?
第二のクラスは、非活動class'はその後、 '' getSharedPreferences方法 –
いくつかの構文、またはそのための方法論についての知識にアクセスするための第二のクラスにコンテキストを渡した '場合は、役立つだろう。たぶん – harshvardhan
[この](http://stackoverflow.com/questions/3549596/sharing-data-amongst-activities-and-services)に役立ちます – GAVD