Saving Game Android

I wanted to apply a saving system to my game so when they exit or it closes, it remember the last scene they were on. Right now here’s how levels are called

 void NextLevel()
    	{
    		Time.timeScale = 1f;
    		if (Application.loadedLevelName != "LevelFour") {
    			Application.LoadLevel (Application.loadedLevel + 1);
    		} else {
    			Application.LoadLevel("Menu");
    		}
    	}

I also have a listener on the same game object to check for Android’s back button being pressed

	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	if (Input.GetKeyDown (KeyCode.Escape)) 
			Application.LoadLevel ("Menu");
		


	}
	void OnApplicationQuit(){
		PlayerPrefs.Save ();
	}
}

Obviously I am trying to use playerprefs to save the game, however I am having trouble implementing it. Since my loaded levels are not actual variables I was wondering the most simple way to implement this? I have never used playerprefs before and I have been reading up on it, I will update if I find something

PlayerPrefs.Save does exactly what it says on the tin, it saves the state of PlayerPrefs data. However you need to push your data into PlayerPrefs in order for it to save.

I would suggest, before you PlayerPrefs.Save(). call the following.

PlayerPrefs.SetString("LastLevel", Application.loadedLevelName);

That will save the name of the last level that was open when it quit.

To read that back in, when your game launches next time you can just go.

string lLastLevel = PlayerPrefs.GetString("LastLevel", "DefaultValue"); 

where “DefaultValue” is probably smart to have as the name of your main menu scene or loading scene that you would normally go through on a first boot.