android - Data in arrays isn't persisted -


in android activitity, using 2 different arrays. first, declaring them, , in oncreate() method, instantiating them. however, when populate them , change orientation, getting instantiated again in , data lost.

public class mainactivity extends activity {      private jsonarray first;     private jsonarray second;      protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          interestedsections = new jsonarray();         productsbought = new jsonarray();     }          //... } 

i tried add if (savedinstancestate != null) before initializing arrays, initialize them first time only, when change orientation, being null. can in order persist data in arrays throughout whole application lifecycle please?

check out answer oncreate called when screen rotated: activity restart on rotation android

edit: if want quick , dirty way make work, have static initialized boolean , set true oncreate. don't set arrays new arrays if initialized true.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -