1. Are you ready for the Galaxy S20? Here is everything we know so far!

Saved State Not Working

Discussion in 'Android Development' started by rukia, Aug 14, 2012.

  1. rukia

    rukia Lurker
    Thread Starter

    Not sure if this is the proper place for this or if this forum is even for developers but here goes. I am having an issue with Saved state. It is simply not working. I am guessing it is because of the spinner initiation on onCreate but am unsure please help.

    Code (Text):
    1.  
    2. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onCreate(Bundle savedInstanceState) {[/SIZE]
    3. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE][/LEFT]
    4.  
    5. [LEFT][SIZE=2]Spinner spinner = (Spinner) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spnrDenomination[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
    6. [SIZE=2]ArrayAdapter<CharSequence> [U]adapter[/U] = ArrayAdapter.[I]createFromResource[/I]([/SIZE]
    7. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], R.array.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]denomination_array[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], android.R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]simple_spinner_item[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
    8. [SIZE=2]adapter.setDropDownViewResource(android.R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]simple_spinner_dropdown_item[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
    9. [SIZE=2]spinner.setAdapter(adapter);[/SIZE]
    10. [SIZE=2]spinner.setOnItemSelectedListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] MyOnItemSelectedListener());[/SIZE][/LEFT]
    11.  
    12.  
    13.  
    14. [SIZE=2]}[/SIZE]
    15.  
    16.  
    17.  
    18. [LEFT][SIZE=2][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
    19. [/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onSaveInstanceState(Bundle savedInstanceState) {[/SIZE][SIZE=2][COLOR=#3f7f5f][/LEFT]
    20. [/COLOR][/SIZE]
    21. [LEFT][SIZE=2]Spinner spinner = (Spinner) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spnrDenomination[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
    22. [SIZE=2]savedInstanceState.putInt([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"MyInt"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], spinner.getSelectedItemPosition());[/SIZE]
    23. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onSaveInstanceState(savedInstanceState);[/SIZE]
    24. [SIZE=2]} [/SIZE][/LEFT]
    25.  
    26.  
    27.  
    28.  
    29.  
    30.  
    31.  
    32. [LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
    33. [/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onRestoreInstanceState(Bundle savedInstanceState) {[/SIZE]
    34. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] myInt = savedInstanceState.getInt([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"MyInt"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    35. [SIZE=2]Spinner spinner = (Spinner) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spnrDenomination[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
    36. [SIZE=2]spinner.setSelection(myInt);[/SIZE]
    37. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onRestoreInstanceState(savedInstanceState);[/SIZE][/LEFT]
    38.  
    39. [SIZE=2]}[/SIZE]
    40.  
    41.  
    42. [/SIZE]
    What am I missing? Thanks in advance for any help.
     


  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator

    Welcome to Android Forums rukia.:)

    I've moved this to the Application Development forum so you can get the help you need.:thumbup:
     
Loading...
Similar Threads - Saved State Working
  1. TechyCoder
    Replies:
    1
    Views:
    258

Share This Page

Loading...