2015-07-20 9 views
5

Ich habe einige sehr einfache Tests mit einem Fragment ausprobiert. Aber Icepick scheint nicht den Wert des String-Test im outstate Bündel zu Speichern ...Ist Icepick defekt?

public class MyFragment extends Fragment { 
    @Icicle String test; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Icepick.restoreInstanceState(this,savedInstanceState); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View view = inflater.inflate(R.layout.fragment_settings, container, false); 
     Log.d(TAG,"restored value of test="+test); 
     return view; 
    } 

    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     test="I have a value"; 
     super.onSaveInstanceState(outState); 
     Icepick.saveInstanceState(this,outState); 
     Log.d(TAG, "test="+test); 
    } 

Mein gradle Build sieht wie folgt aus:

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "com.my31daychallenge.mysleepchallenge" 
     minSdkVersion 15 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:22.2.0' 
    compile 'com.android.support:design:22.2.0' 
    compile 'com.jakewharton.threetenabp:threetenabp:1.0.1' 
    apt 'com.bluelinelabs:logansquare-compiler:1.1.0' 
    compile 'com.bluelinelabs:logansquare:1.1.0' 
    compile 'com.jakewharton:butterknife:7.0.1' 
    compile 'frankiesardo:icepick:3.0.0' 
    provided 'frankiesardo:icepick-processor:3.0.0' 
} 

Hinweis, habe ich versucht, die neueste Version von Icepick 3.0.2 und 3.0.3-SNAPSHOT, keiner von ihnen funktioniert, also dachte ich mir, eine frühere Version mit dem gleichen Ergebnis zu verwenden.

und auch:

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.2.3' 
     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     maven {url "https://clojars.org/repo/"} 
    } 
} 

Was bin ich?

+0

sehen Sie noch dies? Ich habe das gleiche Problem auf 3.1.0 der Bibliothek. – fractalwrench

Antwort

0

setzen Sie Ihre

Icepick.restoreInstanceState(this, savedInstanceState); 

in onCreateView() (statt in onCreate)

Verwandte Themen