android - Best way to load my Sqlite Tables after creating tables on startup -
i have 2 static tables 500 records each provide lookup material listviews in app. when app first starts , tables created run process populate tables takes less minute i've been looking run process in background using async task progress dialog letting user know happening. concern while process running , data being added , user tilts phone process cancel. state of database then? async task best solution or should use threading?
so when rotate or change orientation of phone, activity thing destroyed. don't have rid of async task. in fact live on. don't let task come in , work on ad-hocly.
so if want have activity act if upon rotating can start right up, left off, there method called onretainnonconfigurationinstance(). it's method stashes objects can't parceled in saveinstancestate()
so idea being:
public void oncreate(bundle a) { ... asynctask mytask = getnonconfigurationinstance(); if (mytask == null) { mytask = new asynctask(); mytask.execute(); } ... } public object onretainnonconfigurationinstance() { return mytask; }
this keep async task running, , when oncreate called after rotation pick , needs done.
one thing conscious of progressview. have destroyed , reinitialized new state. overall dismissing of , showing in first place should done outside asynctask. nothing asynctask can't call callback always set in oncreate() notify tell update ui or play sound of completion, etc.
Comments
Post a Comment