简体   繁体   中英

android:configChanges with an Async SQLite Call in onCreate being called when orientation changes

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.

Cleaning the project fixed my issue.

Going to Build > Clean Project .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM