Reputation: 3
I have a recyclerview getting data with http request using Intentservice. I have a button to update my recylcerview adapter. When i push this button data updates and it's seems alright. But when i push this button and change screen orientation, number of rows in recylcler view doubles.
I have this in my manefest:
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize">
So seems like android shouldn't create a new activity with changing orientation and he doesn't when i just change orientation without pushing update button. Anyone got some ideas about that? Thanks.
Upvotes: 0
Views: 106
Reputation: 644
What happen when orientation changed
Life Cycle of orientation
onPause();
onSaveInstanceState();
onStop();
onDestroy();
onCreate();
onStart();
onResume();
Use this
android:configChanges="keyboardHidden|orientation|screenSize"
Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
From http://developer.android.com/guide/topics/resources/runtime-changes.html
Upvotes: 0
Reputation: 1427
Whenever new data found, check old data.
If new data not available in list then insert it. If new data available in list then, check if data is same : nothing to do if data differs : update old data with new data and notify recyclerview itemupdated
You need to specify which data need to update and which not. Apply your logic to compare.
Upvotes: 0
Reputation: 143
Just clear the list before adding the data for first time. so that it will also help you while coming back on the same page.
Upvotes: 0