You will need to keep an array with all the stars collected in local storage or on an sql server. On start of main many layout load the array from the local storage. Lets say cell 0 keeps level 1 stars, cell 1 keeps level 2 stars etc. Then you check each cell value and if cell is equal to 3 then unlock the level. Locking unlocking can be done using different object one clickable the other not, so when level is unlock you make the none clickable object to spawn the clickable one to its position and destroy the none clickable one.
Its pretty hard to get it right on a first try, took me 2-3 days to get it right on my game. Here is a screenshot from my game that might help you.
https://s17.postimg.org/8e17jz1i7/Screenshot_1.jpg
https://s18.postimg.org/epgx2ra8p/Screenshot_2.jpg
https://s22.postimg.org/9fwn1bh0h/Screenshot_3.jpg
Edit: here is the link of the game in the arcade, if you are curious how the menu looks like.
https://www.scirra.com/arcade/puzzle-ga ... sion-18913