How To Get Data From Activity Class To The Phonestatelistener Class?
I have a problem in which I can't get data from activity class to the PhoneStateListener class. for better understanding the code is as below: This is the class from where I want t
Solution 1:
Since you have Context
in both Activity and Receiver
you may use SharedPreference
to set and get data on both places.. WHats the problem..
context.getSharedPreference("name" , MODE_PRIVATE);
Solution 2:
im posting a very simple method to store and get preferences, use this i will solve your problem related to store and retrieve preferences.
publicclassPreferences {
publicstaticvoidrecord(String key,Context context,String value)
{
SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences .Editor editor=pref.edit();
editor.putString(key,value );
editor.commit();
}
publicstaticStringgetRecord(String key,Context context)
{
returnPreferenceManager.getDefaultSharedPreferences(context).getString(key,PREF_DEFAULT_VALUE);
}
}
Post a Comment for "How To Get Data From Activity Class To The Phonestatelistener Class?"