1

I have Parcelable object that holds a query and offset to web API.

Then I have two Activities:

Activity A with a list and Activity B with a ViewPager. User navigates from Activity A to B, and Parcelable is passed in Intent. In Activity A query is persisted using onSaveInstanceState. (initial offset is 0 )

Inside Activity B activity user can swipe and offset can be increased. (offset increased to 20 )

Then user can navigate back to Acitvity A with list. In Activity A query is restored from savedInstanceState. ('offset` is 0 but should be 20 )

What is the best way to maintain such offset state between those two Activities? I want to avoid saving it to shared preferences.

pixel
  • 24,905
  • 36
  • 149
  • 251
  • 1
    Is it possible to replace your two Activities by two fragments? Then you could save your offset to the one Activity that contains the two fragments. – Simulant Dec 05 '13 at 16:57
  • Sounds like storing the value in shared preferences or in a database would be a better solution here. I would probably just go with shared preferences if it's just one value. – James McCracken Dec 05 '13 at 17:15

1 Answers1

1

You can start Activity B 'forResult', and when navigating back to Acivity A, set the result including the offset, so you can access it in Activity A in onAcivityResult() And refresh the value accordingly...

jpm
  • 3,300
  • 1
  • 19
  • 29