Failure delivering result ResultInfo: Invalid state












0















In my app I have a Fragment with a button that asks the user to choose the account using native Android AccountPicker.



Here is how I do it:



 Intent intent = AccountPicker.newChooseAccountIntent(null, null,
new String {"com.google", "com.google.android.legacyimap"},
false, null, null, null, null);
startActivityForResult(intent, PICK_ACCOUNT);


The problem is that if the user backgrounds the entire app while the AccountPicker dialog box is still showing, the Fragment detaches and starts its lifecycle over again but the AccountPicker dialog is still there.



The result is, there is an AccountPicker dialog box on top of black background and proceeding with AccountPicker does nothing. After it gets dismissed the Fragment is recreated so the user has to go through AccountPicker again.



In my Fragment's onCreate() I use



setRetainInstance(true)


My questions are:




  1. Why does my Fragment detaches and goes to black when backgrounded until I dismiss the started AcountPicker? And is there any "hack" to avoid that?

  2. If not, is there any way to "retie" the started AccountPicker activity with the new Fragment?


EDIT:



Found the problem, changing my initial question. So here is what is going on. My Fragment is using an AccountPicker to get the user account to proceed, there is no way my app can proceed without a choosen account (I don't choose a default one). When the entire app is backgrounded while AccountPicker is still running my Main Activity ends its lifecycle and detaches the Fragment too on the way. The AccountPicker however is a separate Activity on the top of the stack so it does not get destroyed, it simply resumes.



I am forcing my Activity to not destroy itself and the Fragment in onStop() however onSavedInstance() is automatically called before onStop() and my Activity state gets saved. That means that I can no longer post Fragment transactions afterwards as it will result in "Lost State" error.



So the new question is: Is there any way to avoid saving Activity state before onStop() if I have to wait for onActivtyResult() to commit Fragment transactions?










share|improve this question





























    0















    In my app I have a Fragment with a button that asks the user to choose the account using native Android AccountPicker.



    Here is how I do it:



     Intent intent = AccountPicker.newChooseAccountIntent(null, null,
    new String {"com.google", "com.google.android.legacyimap"},
    false, null, null, null, null);
    startActivityForResult(intent, PICK_ACCOUNT);


    The problem is that if the user backgrounds the entire app while the AccountPicker dialog box is still showing, the Fragment detaches and starts its lifecycle over again but the AccountPicker dialog is still there.



    The result is, there is an AccountPicker dialog box on top of black background and proceeding with AccountPicker does nothing. After it gets dismissed the Fragment is recreated so the user has to go through AccountPicker again.



    In my Fragment's onCreate() I use



    setRetainInstance(true)


    My questions are:




    1. Why does my Fragment detaches and goes to black when backgrounded until I dismiss the started AcountPicker? And is there any "hack" to avoid that?

    2. If not, is there any way to "retie" the started AccountPicker activity with the new Fragment?


    EDIT:



    Found the problem, changing my initial question. So here is what is going on. My Fragment is using an AccountPicker to get the user account to proceed, there is no way my app can proceed without a choosen account (I don't choose a default one). When the entire app is backgrounded while AccountPicker is still running my Main Activity ends its lifecycle and detaches the Fragment too on the way. The AccountPicker however is a separate Activity on the top of the stack so it does not get destroyed, it simply resumes.



    I am forcing my Activity to not destroy itself and the Fragment in onStop() however onSavedInstance() is automatically called before onStop() and my Activity state gets saved. That means that I can no longer post Fragment transactions afterwards as it will result in "Lost State" error.



    So the new question is: Is there any way to avoid saving Activity state before onStop() if I have to wait for onActivtyResult() to commit Fragment transactions?










    share|improve this question



























      0












      0








      0








      In my app I have a Fragment with a button that asks the user to choose the account using native Android AccountPicker.



      Here is how I do it:



       Intent intent = AccountPicker.newChooseAccountIntent(null, null,
      new String {"com.google", "com.google.android.legacyimap"},
      false, null, null, null, null);
      startActivityForResult(intent, PICK_ACCOUNT);


      The problem is that if the user backgrounds the entire app while the AccountPicker dialog box is still showing, the Fragment detaches and starts its lifecycle over again but the AccountPicker dialog is still there.



      The result is, there is an AccountPicker dialog box on top of black background and proceeding with AccountPicker does nothing. After it gets dismissed the Fragment is recreated so the user has to go through AccountPicker again.



      In my Fragment's onCreate() I use



      setRetainInstance(true)


      My questions are:




      1. Why does my Fragment detaches and goes to black when backgrounded until I dismiss the started AcountPicker? And is there any "hack" to avoid that?

      2. If not, is there any way to "retie" the started AccountPicker activity with the new Fragment?


      EDIT:



      Found the problem, changing my initial question. So here is what is going on. My Fragment is using an AccountPicker to get the user account to proceed, there is no way my app can proceed without a choosen account (I don't choose a default one). When the entire app is backgrounded while AccountPicker is still running my Main Activity ends its lifecycle and detaches the Fragment too on the way. The AccountPicker however is a separate Activity on the top of the stack so it does not get destroyed, it simply resumes.



      I am forcing my Activity to not destroy itself and the Fragment in onStop() however onSavedInstance() is automatically called before onStop() and my Activity state gets saved. That means that I can no longer post Fragment transactions afterwards as it will result in "Lost State" error.



      So the new question is: Is there any way to avoid saving Activity state before onStop() if I have to wait for onActivtyResult() to commit Fragment transactions?










      share|improve this question
















      In my app I have a Fragment with a button that asks the user to choose the account using native Android AccountPicker.



      Here is how I do it:



       Intent intent = AccountPicker.newChooseAccountIntent(null, null,
      new String {"com.google", "com.google.android.legacyimap"},
      false, null, null, null, null);
      startActivityForResult(intent, PICK_ACCOUNT);


      The problem is that if the user backgrounds the entire app while the AccountPicker dialog box is still showing, the Fragment detaches and starts its lifecycle over again but the AccountPicker dialog is still there.



      The result is, there is an AccountPicker dialog box on top of black background and proceeding with AccountPicker does nothing. After it gets dismissed the Fragment is recreated so the user has to go through AccountPicker again.



      In my Fragment's onCreate() I use



      setRetainInstance(true)


      My questions are:




      1. Why does my Fragment detaches and goes to black when backgrounded until I dismiss the started AcountPicker? And is there any "hack" to avoid that?

      2. If not, is there any way to "retie" the started AccountPicker activity with the new Fragment?


      EDIT:



      Found the problem, changing my initial question. So here is what is going on. My Fragment is using an AccountPicker to get the user account to proceed, there is no way my app can proceed without a choosen account (I don't choose a default one). When the entire app is backgrounded while AccountPicker is still running my Main Activity ends its lifecycle and detaches the Fragment too on the way. The AccountPicker however is a separate Activity on the top of the stack so it does not get destroyed, it simply resumes.



      I am forcing my Activity to not destroy itself and the Fragment in onStop() however onSavedInstance() is automatically called before onStop() and my Activity state gets saved. That means that I can no longer post Fragment transactions afterwards as it will result in "Lost State" error.



      So the new question is: Is there any way to avoid saving Activity state before onStop() if I have to wait for onActivtyResult() to commit Fragment transactions?







      android android-fragments android-lifecycle accountpicker






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 2:43







      Romaldowoho

















      asked Nov 14 '18 at 0:44









      RomaldowohoRomaldowoho

      156415




      156415
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291573%2ffailure-delivering-result-resultinfo-invalid-state%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291573%2ffailure-delivering-result-resultinfo-invalid-state%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma