Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Game freezes after you cancel Android share intent

Discussion in 'WebGL' started by Good_Punk, Jun 7, 2021.

  1. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    Hello,
    a very specific question here... I'm trying to share an URL with the share intent in my WebGL game on Android. This is the code:

    Code (JavaScript):
    1.     ShareIntent: function(setUrl) {
    2.         var shareData = {
    3.             title: 'Invite a Friend',
    4.             text: 'Come play with me in this game!',
    5.             url: Pointer_stringify(setUrl),
    6.         };
    7.         try {
    8.             navigator.share(shareData);
    9.         } catch(err) {
    10.             console.log("Browser doesn't support sharing: " + err);
    11.         }
    12.     }
    It works like a charm... well almost. If I don't actually share the URL but tap on the background which closes the share overlay, the game doesn't resume but is frozen and you need to reload the website.
    If you do actually share the URL you can go back to the website and it works normally.

    Any idea how I could prevent the freeze on cancelling the share intent?
     
  2. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    Ok so normally you would call the navigator.share with an "await" as an async function... but that doesn't work with WebGL. (Get a build error then). So does anyone have a workaround for that maybe?
     
  3. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    Ok I've changed the call to:
    navigator.share(shareData)
    .then(function() {console.log("did share")})
    .catch(function(error) {console.log("error: ",error)});
    but with the same result. Another interesting find is that after reloading the page other JS functions seem to be broken... I'm using a JS plugin for TextInput fields on Mobile and that stops working once I've called the Navigator.Share function. Have to restart the whole browser to get it back to work. Oo
     
  4. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    552
    My guess is that the game canvas loses it's focus.
    you can have an animation on the background, and you'll see that it still works. My guess is that only EventSystem and Touch/Mouse inputs won't work.

    You'll need to find a solution to get back the focus
     
  5. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    Thanks, that sounded plausible. Unfortunately after testing with an animation this doesn't seem to be the case. The animation stops when the share intent popup comes up and doesn't resum afterwards.
     
  6. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    I've tried to do a reload with "document.location.reload()" after the share as a wonky workaround that you can at least continue playing. Unfortunately that results in a Runtime Error Memory Access out of Bounds on some devices. :(