程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-onSaveInstanceState()保存數值

android-onSaveInstanceState()保存數值

編輯:編程綜合問答
onSaveInstanceState()保存數值

需要在onSaveInstanceState()中保存數組列表的值,數值是來自onCreat方法的數組。但是系統運行後報錯。

public void onSaveInstanceState(Bundle savedInstanceState) {
    savedInstanceState.putParcelable("Old", (Parcelable) profileDetails );
    super.onSaveInstanceState(savedInstanceState);
}

在onCreate()

if (savedInstanceState != null) { 
    profileDetails= (ArrayList<ProfileDetails>)savedInstanceState.getParcelable("Old");
}
else {
    profileDetails = GetSearchResults();
}

最佳回答:


- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addAnimation:) name:UIApplicationWillEnterForegroundNotification object:nil];

}

- (void)addAnimation:(NSNotification *)notificaiton
 {
 CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
 animation.fromValue = [NSNumber numberWithFloat: 2*M_PI];
 animation.toValue = [NSNumber numberWithFloat:0.0f];
 animation.duration = 4.0f;
 animation.repeatCount = INFINITY;
 [imageLeft.layer addAnimation:animation forKey:@"SpinAnimation"];
 [imageRight.layer addAnimation:animation forKey:@"SpinAnimation"];
 }
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved