article id #182 categorized under My/Diary & written by 김민수
2개월 가량 먹을것도 못먹고, 잠도 덜자고? 참 오랫동안 준비 한 공모전 앱입니다.
중간에 데이터베이스 설계잘못 해서 소스 뒤업고, 기획을 잘 못해서 몇일 허비 했습니다.
프로그램 개발에서 기획/설계능력이 중요한것을 다시한번 느낌니다..
아직 갈길은 멀었고, 출품 마감일은 다가 오고..
이번엔 좋은 결과 있기를..
안드로이드 화면 회전시 OnDestory(), OnCreate()등이 호출 되면서 기존의 변수들이 모두 초기화 되어 버린다.
이러한 데이터 초기화를 방지하기 위해 화전회전시 onRetainNonConfigurationInstance()이 호출 되는데 이때,
데이터를 저장하여 화면회전후 다시 불러오는 방법이다.
@Override
public Object onRetainNonConfigurationInstance()
{
//HashMap을 이용하여 데이터를 저장
HashMap data= new HashMap();
data.put("year", year);
data.put("month", month);
return data;
}
@SuppressWarnings("unchecked")
private void restore()
{
//데이터를 불러온다.
Object obj = getLastNonConfigurationInstance();
if(obj!=null)
{
HashMapdata = (HashMap) obj;
this.year = Integer.parseInt(data.get("year").toString());
this.month = Integer.parseInt(data.get("month").toString());
}
}
On current Android devices, we can keep only a small handful of applications
running at the same time. Having your application do this is going to going
to take resources from other things that at any particular point in time
would be better used elsewhere. And in fact, you can be guaranteed that
your service will -not- stay running all of the time, because there is so
much other stuff that wants to run (other background services that are only
running when needed will be prioritized over yours), or needs more memory
for what the user is actually doing (running the web browser on complicated
web pages is a great way to kick background stuff out of memory).
We have lots of facilities for implementing applications so they don't need
to do this, such as alarms, and various broadcasts from events going on in
the system. Please please please use them if at all possible. Having a
service run forever is pretty close to the side of evil.
지나치게 긴 작업의 경우 작업도중 죽게 된다고하네요. 이럴경우 쓰레드로 빼서 구현해야 될것 같네요..