본문 바로가기

Android의 Context ( getBaseContext()와 getApplicationContext() 차이) Android의 Context 정리 1) getBaseContext() Activity의 Context 생성자나 Context에서 기본 설정 된 Context 2) getApplicationContext() Service의 Context 어플리케이션의 종료 이후에도 활동 가능한 글로벌한 Application의 Context 앱 종료 후 메모리 유지를 피하기 위해서 getBaseContext를 사용. 3) View.getContext() 현재 실행되고 있는 View의 context를 return 하는데 보통은 현재 활성화된 activity의 context가 된다. 4) Activity.getApplicationContext() 어플리케이션의 Context가 return된다. 현재 activiy의 conte.. 더보기
한국나이 계산하기 FROM yyyymmdd format yyyymmdd format으로부터 한국나이 계산 public static int calculateAgeForKorean(String ssn) { // ssn의 형식은 yyyymmdd 임 String today = ""; // 오늘 날짜 int manAge = 0; // 만 나이 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); today = formatter.format(new Date()); // 시스템 날짜를 가져와서 yyyyMMdd 형태로 변환 // today yyyyMMdd int todayYear = Integer.parseInt(today.substring(0, 4)); int todayMonth = Integer.parseInt.. 더보기
JSON String을 JSONObject로 변환하기 JSON String을 JSONObject로 변환하기 자바 또는 안드로이드 통신을 하기 위해 타입은 스트링(String)이지만 데이터 값은 JSON 상태를 가지고 있을 수 있다. 예) String test = {"text" : [ { "code" : "011", "responsetext" : "응답입니다." } ] }; (문법 무시) 이런식을 어떻게 파싱해야 되는지 고민했는데 다행히 JSONObject로 변경할수 있는 방법이 있었네요 JSONObject json = null; json = new JSONObject(test); 참고 블로그 : http://heavenow.tistory.com/23 더보기