0

I am populating a ListView with the contents of an SQLite database. In my onCreate method in my StartList activity I call an AsyncSQLite which reads data from a JSON url and adds the data to the SQlite database.

But every time that I change my screen orientation, my app is calling the AsyncSQLite method again. I have added android:configChanges="orientation|keyboardHidden|screenSize" to my AndroidManifest.xml but that doesn't seem to be making a difference.

Here is my onCreate method from my StartList activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start_List);

    oslist.clear();
    oslist = new ArrayList<LinkedHashMap<String, String>>();
    new AsyncSQLite().execute();
}

Here is my AndroidManifest.xml:

<activity
    android:name=".StartList"
    android:label="@string/title_activity_start_List"
    android:parentActivityName=".MainActivity"
    android:configChanges="orientation|keyboardHidden|screenSize">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity" />
</activity>

I thought that onCreate should only be called once when the activity is being created, but instead it is being called whenever I change the orientation.

mhorgan
  • 886
  • 2
  • 11
  • 32
  • [http://stackoverflow.com/questions/7128670/best-practice-asynctask-during-orientation-change](http://stackoverflow.com/questions/7128670/best-practice-asynctask-during-orientation-change) – M D Aug 31 '15 at 12:41
  • "I thought that onCreate should only be called once when the activity is being created" - This is a misconception, see http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle and http://developer.android.com/guide/topics/resources/runtime-changes.html – JimmyB Aug 31 '15 at 12:45
  • It work correctly, Try to clear you project. Don't use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); at your activity. – eurosecom Aug 31 '15 at 15:09

1 Answers1

0

Cleaning the project fixed my issue.

Going to Build>Clean Project.

mhorgan
  • 886
  • 2
  • 11
  • 32