[Activity #1] onSaveInstanceState()
반응형
Called to retrieve per-instance state from an activity before being killed so that the state can be restored in onCreate(Bundle) oronRestoreInstanceState(Bundle) (the Bundle populated by this method will be passed to both). |
Activity 내에서 화면이 전환된다던지, 특정 상황에 Activity에서 사용하던 정보를 저장하고 싶은데 사용하면됩니다.
기본 흐름.
1. 호출될때 데이타를 저장합니다.
public class SearchActivity extends Activity {
private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
private String mCity = "";
........
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("mAppWidgetId", mAppWidgetId);
outState.putString("mCity", mCity);
......
}
2. Oncreate에서 데이타를 꺼내면 됩니다.
public void onCreate(Bundle savedInstanceState)
{
if(savedInstanceState == null){
........
}else{
........
mAppWidgetId = savedInstanceState.getInt("mAppWidgetId");
mCity = savedInstanceState.getString("mCity");
........
}
간단하죠.
반응형
'IT > Android[안드로이드]' 카테고리의 다른 글
[Serializable] 객체를 파일에 쓰고 읽기 (0) | 2010.12.03 |
---|---|
[DateFormat] 시간정보 가져오기 (2) | 2010.12.03 |
[Intent #1] Activity에 기본 데이타 전달하기 (0) | 2010.12.01 |
[Intent #2] Activity간 정보 전달 [Parcelable] (0) | 2010.12.01 |
[ListView #4] 사용자 Layout을 이용한 List (0) | 2010.11.25 |