Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml5 Canvas working in WebView of Main Activity but stops working in WebView of Activity called using an intent in the same application
    primarykey
    data
    text
    <p>The device I'm testing on is running Android 2.3.4.</p> <p>I have a Html5/JavaScript game. </p> <p>Initially I had my menu and game in the same Activity and it worked fine. I just loaded the game URL from the Assets folder. </p> <p>I wanted to changed it so that I launch the game in a new Activity:</p> <pre><code> Intent gameIntent = new Intent(_context, GameActivity.class); gameIntent.putExtra("gameLocation", "file:///android_asset/game/index.html"); ((Activity) _context).startActivity(gameIntent); </code></pre> <p>Then I load it in the new Activity:</p> <pre><code>gameWebView.loadUrl(getIntent().getStringExtra("gameLocation")); </code></pre> <p>I use the very same settings for the WebView in both Activities with JavaScript enabled etc.</p> <p>The standard HTML buttons and text render fine but the canvas element does not render although the correct amount of space is still taken up by the element.</p> <p>I have no idea why it is not working. I even tried pointing the WebView to an online Html Canvas game and that doesn't work either. Edit: The game I pointed to does work in my standard phone browser and in the WebView of the Activity I have set as the launcher i.e.:</p> <pre><code>&lt;activity android:name=".MainActivity" android:configChanges="keyboardHidden|orientation" android:launchMode="singleTask" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>My main Activity where the game works has its launch mode set to single task. I have tried both standard and singleTop for the game Activity. </p> <p>Any ideas what could be going wrong here?</p> <p><strong>EDIT:</strong> I have also tried setting the GameActivity to be the launcher and the Canvas element works. It appears that the problem only occurs when running the game in the Activity that has been launched as an Intent.</p> <p><strong>Yet another EDIT</strong> (this problem is really getting to me):</p> <p>I think the problem stems from the fact both Activities are using WebViews. They point to completely different resources in my assets folder but Activity A(Main) is running JavaScript, then Activity B (GameActivity) is called with an intent and the Canvas doesn't render. If I replace Activity A with a plain Activity that has no WebView and just a button to launch Activity B, then the Canvas works in Activity B. In an attempt to fix that I call finish on Activity A as I start the intent for B but that still didn't work. Not sure what kind of an answer I'm expecting to this but maybe someone here knows the inner workings of all this and has a possible solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload