This is an advanced inventory example similar to Terraria; Demo for the Scirra Store- link in description.
how this works when i go to next layout, all items are saved?
No. The data is stored in the inventory slots via instance variables. I made this a while back and to be honest it probably would have been better to take an approach using an array for data storage.