0

Activity 1:SelectBatchStep. RecyclerView populated with MySQL database data

Activity 2: DoneBy. Simple activity inserting new data in the database.

Activity 1 is reloaded after Activity 2 finishes in order to show the updated recyclerView item.

I am trying to save the scrolling position in a recyclerview activity 1. I start a new activity 2 but the scroll position is not recovered when I call back the recyclerview activity 1.

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    savedInstanceState.putInt(SCROLL,scrollpositionkeeper);
    super.onSaveInstanceState(savedInstanceState);
    Log.v(TAG,"scrollpositionsaved"+savedInstanceState);
}

Logcat shows the bundle Is saved and the scroll position is correctly saved when I start the new activity 2.

Activity 2 is started from the recycler adapter using com.daimajia.swipe.SwipeLayout library.

Activity 1 is recalled from activity 2 as follows:

Intent intent1 = new Intent(DoneBy.this, SelectBatchStep.class);

Activity 1 has the following:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        scrollrecovered = savedInstanceState.getInt(SCROLL);
    }
    else {
        scrollrecovered=0;
    }
    Log.v(TAG,"scrollpositionrecovered"+savedInstanceState);
    setContentView(R.layout.activity_select_batch_step);

Activity 1 comes to the front and logcat shows that the Bundle is null

Why is the saved bundle null?

chemitron
  • 3
  • 2
  • 1
    Possible duplicate of [Android: onSaveInstanceState not being called from activity](https://stackoverflow.com/questions/12793069/android-onsaveinstancestate-not-being-called-from-activity) – ericn Apr 20 '18 at 02:00
  • Thanks ericn for the link. I see your point. I am intentionally starting a new Activity 1 after Activity 2 is done. So, how can I save the scroll position for Activity 1? I need to refresh the data from MySQL in activity 1 in order to show the new data inserted during Activity 2 – chemitron Apr 20 '18 at 02:15
  • i think you need callback to activity1 or register broadcastrecevier , simple and quickly method is set one tag to recycleView ,the tag is record position. – user9672625 Apr 20 '18 at 02:20
  • user9672625 could you elaborate your answer with more details? Thanks – chemitron Apr 21 '18 at 01:09

0 Answers0