Android Notepadv1 Tutorial - Persistent mNoteNumber?
        Posted  
        
            by Chris L.
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chris L.
        
        
        
        Published on 2010-05-21T21:47:22Z
        Indexed on 
            2010/05/21
            21:50 UTC
        
        
        Read the original article
        Hit count: 213
        
So I did the Notepadv1 tutorial. It worked great. No problems. I would however like some explanation on why the mNoteNumber remembers the last number of the item I created.
So the class starts as follows:
public class Notepadv1 extends ListActivity {
     private int mNoteNumber = 1;
That's fine, I understand that. The only other time the mNoteNumber variable is used is when you add an item it creates a note with that number and then increments it to the next number as follows:
private void createNote() {
 String noteName = "Note " + mNoteNumber++;
Those are the only two references to the variable mNoteNumber. When I press the Home button and then reopen the app, I add a new note but instead of adding a second "Note 1" it remembers that the last note I added as "Note 3" so it makes "Note 4". So I don't get it. Does Java/Android remember the last state of variables?
If anyone could give me some explanation that would be great THANKS!
© Stack Overflow or respective owner