0

1) When I click an item in a RecyclerView in Activity A, it takes me to another Activity B, when I navigate back from that Activity B back to A, A somehow calls onStart/onCreate and the RecyclerView data that I was scrolled at all changes. How to prevent this?

2) Say I have an Activity A and Activity B where I have buttons in both that navigate to Activity C. When I go back from Activity C, I want to determine which Activity I came from, A or B, to navigate back to. In AndroidManifest, I can only put ONE ParentActivity, so I don't know how to go about doing this.

bycfly
  • 341
  • 3
  • 13
  • onCreate might be called once the activity was previously destroyed due to low memory – Zun Apr 30 '18 at 14:53

2 Answers2

0
  1. onStart() will be called when resume activity A from B. You have to save the last scroll position of recyclerview yourself. you can refer to this answer

  2. Not sure how you implement the navigation to activity C. If you use startActivityForResult() in A and B then you can override onActivityResult() in A and B to get the data from C

h0102
  • 236
  • 3
  • 11
0

1) When I click an item in a RecyclerView in Activity A, it takes me to another Activity B, when I navigate back from that Activity B back to A, A somehow calls onStart/onCreate and the RecyclerView data that I was scrolled at all changes. How to prevent this?

Instead of startActivity() start Activity B using startActivityForResult(). You can refer to this SO to implement it.

when I navigate back from that Activity B back to A, A somehow calls onStart/onCreate

onStart() will be called because Activity A entered onStop() after launching Activity B using startActivity()

onCreate() might be called if OS is under memory pressure and destroys your activity to relinquish some memory. It will recreate it before its being displayed back to user.

Refer to Activity lifecycle document.

Say I have an Activity A and Activity B where I have buttons in both that navigate to Activity C. When I go back from Activity C, I want to determine which Activity I came from, A or B, to navigate back to.

You can use startActivityForResult() here too.

Note: You need to be aware of potential issue with onStartActivity() getting called pre-maturely. Refer to this SO

Sagar
  • 23,903
  • 4
  • 62
  • 62