메인액티비티에서 SharedPreferences에 위도, 경도 값을 저장하구요.
Class에서 그 값을 불러오기할 때 getSharedPreferences에서 계속 빨간줄이 떠서
Context를 이용해 돌려봤습니다. 코딩상 문제는 없는데
계속 파일을 못불러 오네요. 문제가 뭘까요?
어떻게 해야하나요ㅠ
public class MainActivity extends Activity {
private SharedPreferences prvPrefLocation;
private SharedPreferences.Editor editorLat;
private SharedPreferences.Editor editorLon;
prvPrefLocation = getSharedPreferences("Location_pf", Context.MODE_PRIVATE);
editorLat = prvPrefLocation.edit();
editorLon = prvPrefLocation.edit();
editorLat.putString("lat", Double.toString(Lat));
editorLon.putString("lon", Double.toString(Lon));
editorLon.commit();
editorLon.commit();
////값 불러오는 클래스
public class GmailClient {
private Context mContext=null; // private Context mContext; null값 없이도 선언해서 돌려봄
private SharedPreferences prvPrefLocation;
double Dlat;
double Dlon;
public void setAccountDetails(String userName, String password){
this.userName = userName;
this.password = password;
}
public List<String> readGmail() throws MessagingException{
receivingHost="imap.gmail.com";
Properties props=System.getProperties();
props.setProperty("mail.store.protocol","imaps");
Session session = Session.getDefaultInstance(props);
prvPrefLocation = mContext.getSharedPreferences("Location_pf", Context.MODE_PRIVATE);
String slat= prvPrefLocation.getString("lat", "");
String slon= prvPrefLocation.getString("lon", "");
this.Dlat = Double.parseDouble(slat);
this.Dlon = Double.parseDouble(slon);