0

My question is very simple.

When an activity run the onCreate() function executes. However when I rotate the iPhone it seems the OnCreate runs again.

I access a remote database to get rows of data. Is there a On????() function that get called only ONCE per activity or Do I need to check if the device rotates to prevent from re-reading the database.

I want to be able to rotate but only access the db once if possible.

Thanks

user6804473
  • 165
  • 2
  • 2
  • 6
  • 1
    Possible duplicate of [Activity restart on rotation Android](http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android) – Barend Sep 18 '16 at 20:23
  • Do you have `Android` OS on your `iPhone`?...Change the approach. E.g. use a singleton for the remote calls. Read [Activity Lifecycle](https://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle) – Onik Sep 18 '16 at 20:24

1 Answers1

1

Yes, onCreate() will be executed after each device rotation, if did not configured android:configChanges Activity attribute properly in your AndroidManifest.xml

Usually it's OK to reread data in this case.

But if you cares about traffic, you should cache locally the data you have read from remote server. Use SQLite database to store the data and timestamp when you got it.

Andrey Kopeyko
  • 1,556
  • 15
  • 14