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