Android Question Can an Activity force re-creation of itself.

Discussion in 'Android Questions' started by agraham, Jul 4, 2019.

  1. agraham

    agraham Expert Licensed User

    I may be over-thinking this one and maybe missing the obvious but ...

    Is it possible for an Activity to force its own re-creation, as if the device was rotated, so the Activity is destroyed and Activity_Create runs again. I would like to to set some Process Globals in an Activity to guide its re-creation then force its own recreation.

    It looks like using StartActivity("<MyActivityName>") within the activity does indeed restart it and it looks like it might just re-create it and not duplicate the activity on the Activity stack as I would expect, but can anyone confirm this and that there are no unfortunate things happening in the background?

    EDIT: It looks like StartActivity might indeed duplicate the Activity and so will no do for what I want!
  2. Erel

    Erel Administrator Staff Member Licensed User

    Don't use strings.
    This should work:
  3. agraham

    agraham Expert Licensed User

    Thanks Erel, that seems to work fine. If anyone else tries this note that UserClosed in the Activity_Pause event will be True, so you might need a flag variable to tell the Pause event code what is happening.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice