Where should I be using getIntent() in the Android lifecycle












0














I have a bug in my app which I thought I knew how to resolve, but now I've thought more about what is happening I'm not sure I do know the fix.



My app receives an incoming intent from a calling third party app as a string. That string can be sent as a SEND intent or a VIEW intent.



All of that works fine unless the app is already running...



This is what is happening:




  1. My app is not running (not listed in the running apps view)

  2. Share is clicked in another (third party) app and my app is selected to receive the shared text (text1).

  3. My app opens and the text is displayed (and processed) as expected.

  4. The user switches back to the third party app and shares some different text (text2) and my app is selected to receive this new text.

  5. My app opens, but the original text (text1) is still displayed.


At this point I thought that the bug was because I am reading the intent in onCreate() and then displaying and processing it. My thinking was that as the app is already running onCreate() is not being called when the app is shown the second time as we jump into the lifecycle at onResume().



However, if I continue the test as follows:




  1. Without exiting my app the user switches back to the third party app again and again shares the same piece of second text (text2) with my app.

  2. My app is displayed again but this time correctly shows and processes the second text.


How can this be, as the app is still running, surely onCreate() is still not going to be called!



I thought that the fix was going to be simply to move the getIntent() call into onResume() (or onStart() ?) But now I'm not sure about this. Is this right thing to do?










share|improve this question
























  • What launch mode do you have set on your activity? android:launchMode developer.android.com/guide/topics/manifest/activity-element
    – Dom
    Nov 21 '18 at 23:47
















0














I have a bug in my app which I thought I knew how to resolve, but now I've thought more about what is happening I'm not sure I do know the fix.



My app receives an incoming intent from a calling third party app as a string. That string can be sent as a SEND intent or a VIEW intent.



All of that works fine unless the app is already running...



This is what is happening:




  1. My app is not running (not listed in the running apps view)

  2. Share is clicked in another (third party) app and my app is selected to receive the shared text (text1).

  3. My app opens and the text is displayed (and processed) as expected.

  4. The user switches back to the third party app and shares some different text (text2) and my app is selected to receive this new text.

  5. My app opens, but the original text (text1) is still displayed.


At this point I thought that the bug was because I am reading the intent in onCreate() and then displaying and processing it. My thinking was that as the app is already running onCreate() is not being called when the app is shown the second time as we jump into the lifecycle at onResume().



However, if I continue the test as follows:




  1. Without exiting my app the user switches back to the third party app again and again shares the same piece of second text (text2) with my app.

  2. My app is displayed again but this time correctly shows and processes the second text.


How can this be, as the app is still running, surely onCreate() is still not going to be called!



I thought that the fix was going to be simply to move the getIntent() call into onResume() (or onStart() ?) But now I'm not sure about this. Is this right thing to do?










share|improve this question
























  • What launch mode do you have set on your activity? android:launchMode developer.android.com/guide/topics/manifest/activity-element
    – Dom
    Nov 21 '18 at 23:47














0












0








0







I have a bug in my app which I thought I knew how to resolve, but now I've thought more about what is happening I'm not sure I do know the fix.



My app receives an incoming intent from a calling third party app as a string. That string can be sent as a SEND intent or a VIEW intent.



All of that works fine unless the app is already running...



This is what is happening:




  1. My app is not running (not listed in the running apps view)

  2. Share is clicked in another (third party) app and my app is selected to receive the shared text (text1).

  3. My app opens and the text is displayed (and processed) as expected.

  4. The user switches back to the third party app and shares some different text (text2) and my app is selected to receive this new text.

  5. My app opens, but the original text (text1) is still displayed.


At this point I thought that the bug was because I am reading the intent in onCreate() and then displaying and processing it. My thinking was that as the app is already running onCreate() is not being called when the app is shown the second time as we jump into the lifecycle at onResume().



However, if I continue the test as follows:




  1. Without exiting my app the user switches back to the third party app again and again shares the same piece of second text (text2) with my app.

  2. My app is displayed again but this time correctly shows and processes the second text.


How can this be, as the app is still running, surely onCreate() is still not going to be called!



I thought that the fix was going to be simply to move the getIntent() call into onResume() (or onStart() ?) But now I'm not sure about this. Is this right thing to do?










share|improve this question















I have a bug in my app which I thought I knew how to resolve, but now I've thought more about what is happening I'm not sure I do know the fix.



My app receives an incoming intent from a calling third party app as a string. That string can be sent as a SEND intent or a VIEW intent.



All of that works fine unless the app is already running...



This is what is happening:




  1. My app is not running (not listed in the running apps view)

  2. Share is clicked in another (third party) app and my app is selected to receive the shared text (text1).

  3. My app opens and the text is displayed (and processed) as expected.

  4. The user switches back to the third party app and shares some different text (text2) and my app is selected to receive this new text.

  5. My app opens, but the original text (text1) is still displayed.


At this point I thought that the bug was because I am reading the intent in onCreate() and then displaying and processing it. My thinking was that as the app is already running onCreate() is not being called when the app is shown the second time as we jump into the lifecycle at onResume().



However, if I continue the test as follows:




  1. Without exiting my app the user switches back to the third party app again and again shares the same piece of second text (text2) with my app.

  2. My app is displayed again but this time correctly shows and processes the second text.


How can this be, as the app is still running, surely onCreate() is still not going to be called!



I thought that the fix was going to be simply to move the getIntent() call into onResume() (or onStart() ?) But now I'm not sure about this. Is this right thing to do?







android android-intent android-activity android-lifecycle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 16:00







Fat Monk

















asked Nov 21 '18 at 22:57









Fat MonkFat Monk

750934




750934












  • What launch mode do you have set on your activity? android:launchMode developer.android.com/guide/topics/manifest/activity-element
    – Dom
    Nov 21 '18 at 23:47


















  • What launch mode do you have set on your activity? android:launchMode developer.android.com/guide/topics/manifest/activity-element
    – Dom
    Nov 21 '18 at 23:47
















What launch mode do you have set on your activity? android:launchMode developer.android.com/guide/topics/manifest/activity-element
– Dom
Nov 21 '18 at 23:47




What launch mode do you have set on your activity? android:launchMode developer.android.com/guide/topics/manifest/activity-element
– Dom
Nov 21 '18 at 23:47












1 Answer
1






active

oldest

votes


















1














The core of the issue is the fact that your Activity is already on top of the activity stack when the second Intent is being fired.



The launch mode will matter here.



What you can do is, set the launchMode to singleTop, and then get the intent in onNewIntent() method.



That is a good way of handling such scenarios. Please read the link above and it will make things very clear.






share|improve this answer





















    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%2f53421612%2fwhere-should-i-be-using-getintent-in-the-android-lifecycle%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The core of the issue is the fact that your Activity is already on top of the activity stack when the second Intent is being fired.



    The launch mode will matter here.



    What you can do is, set the launchMode to singleTop, and then get the intent in onNewIntent() method.



    That is a good way of handling such scenarios. Please read the link above and it will make things very clear.






    share|improve this answer


























      1














      The core of the issue is the fact that your Activity is already on top of the activity stack when the second Intent is being fired.



      The launch mode will matter here.



      What you can do is, set the launchMode to singleTop, and then get the intent in onNewIntent() method.



      That is a good way of handling such scenarios. Please read the link above and it will make things very clear.






      share|improve this answer
























        1












        1








        1






        The core of the issue is the fact that your Activity is already on top of the activity stack when the second Intent is being fired.



        The launch mode will matter here.



        What you can do is, set the launchMode to singleTop, and then get the intent in onNewIntent() method.



        That is a good way of handling such scenarios. Please read the link above and it will make things very clear.






        share|improve this answer












        The core of the issue is the fact that your Activity is already on top of the activity stack when the second Intent is being fired.



        The launch mode will matter here.



        What you can do is, set the launchMode to singleTop, and then get the intent in onNewIntent() method.



        That is a good way of handling such scenarios. Please read the link above and it will make things very clear.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 0:48









        codeFoodcodeFood

        8661111




        8661111






























            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%2f53421612%2fwhere-should-i-be-using-getintent-in-the-android-lifecycle%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'