Can a configuration change occur after startActivityForResult was called?
Asked Answered
R

0

7

Given the following situation (partially pseudo-code):

  1. User presses a button in Activity A which in turn executes this code:
    progressBar.setVisibility(VISIBLE) // by default is set as INVISIBLE in the layout
    startActivityForResult(ActivityB)
  1. User rotates his device

Is it possible that step 2 (rotating device) causes a configuration change which leads to the recreation of Activity A and therefore the progressBar to be hidden before Activity B is shown? I know that startActivityForResult is an asynchronous call, but I am not sure how it is implemented internally, therefore if the configuration change in Activity A can occur before Activity B is shown?

Realistic answered 21/11, 2020 at 19:20 Comment(4)
Personally, I'd try to set it up such that it doesn't matter either way. This feels like one of those things that might be different based on Android version.Binette
Why would you use a progressbar in A if you just started B? Is the bar even visible? How would you update it from B? I do not understand this construction.Eulogist
@Eulogist I just switched the two lines to make it more intuitive. Starting Activity B takes longer than I would like it to do so I show a ProgressBar. While implementing it, I came up with the question if a configuration change could hide the ProgressBar before Activity B is shown. It's more about learning and curiousity than about an practical issue.Realistic
@Binette Practically seen I guess one won't notice a difference between restoring the ProgressBar on a configuration change (if that can happen) and not doing so, but I am wondering if it's possible at all that a configuration change can happen. If that's the case, I would implement the few lines for saving and restoring the loading state, otherwise I would skip it ;-) It's more about learning and curiousity of course, asking the question likely took longer than implementing it ;-)Realistic

© 2022 - 2024 — McMap. All rights reserved.