Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click events not registered

This is the main screen of the Android app. Everything's rendered inside a WebView.

When I hit the button in the bottom left corner, this overlay opens, with its contents dynamically added to it.

When I hit one of the icons, it should get added to the bar on the left. And so it does.

When I hit another icon, though, nothing happens at all. The function it should call does not run (I checked by putting an alert () at the beginning of it).

When I close the overlay (button in the top left corner), and open it again (bottom left), I can add another icon. But yet again, the next event will not trigger until the overlay is closed and opened once more.

I don't know how easy this is going to be to fix, as I'm not sure whether everyone experiences this issue. I (on my Samsung GT-P6200 running Android 4.0.4) do. Someone else complained to me about it as well. In the Android emulator included in the SDK, however, no such thing seems to occur with Android 4.1 and 4.1. It seems to be a 4.0 problem.

An icon in the overlay looks like this; <div class="appLauncher" onClick="launchApp (' + i + ')"><img src="data:image/png;base64,' + base64 + '" alt="[~]" /><br /><span>' + label + '</span></div>

I use jQuery to mess around with the DOM, if it makes any difference.

function launchApp (i)
{
    // Putting an alert () here indicates that the function doesn't get called, because no alert box appears on the screen //
    try
    {
        if (! launcherEdit)
        {
            android.launchAppFromList (i);
        }
        else
        {
            addAppToLauncherFromList (i); // This is what should happen //
        }
    }
    catch (ex)
    {
        handleException (ex);
    }
}

The app itself can be found here; https://play.google.com/store/apps/details?id=be.robinj.ubuntu
It's source code can be found here; http://bazaar.launchpad.net/~robinj/be.robinj.ubuntu/trunk/files
And this is the Javascript file; http://bazaar.launchpad.net/~robinj/be.robinj.ubuntu/trunk/view/head:/assets/script.js


And please, just please, don't close this as an "exact duplicate" without properly understanding what the actual issue is, like has happened plenty of times before.


This bloody mess only seems present on Android 4.0.4 and lower (or somewhere around that version number). It's only clicks on the appLaunchers that are complete ignored.


I'm starting to see some kind of connection here... It always starts failing after the jQuery animation adding the item to the left bar has played. This is starting to look suspiciously like a redrawing issue...


Not sure whether this is related, but saw it popping up in my console...

02-12 14:30:22.650: E/dalvikvm(3936): JNI ERROR (app bug): attempt to use stale global reference 0xe
02-12 14:30:22.650: E/dalvikvm(3936): VM aborting
02-12 14:30:22.650: A/libc(3936): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)
like image 311
RobinJ Avatar asked Feb 05 '13 13:02

RobinJ


People also ask

Does click event work on mobile?

Rise of MobileOn a phone, mouse click doesn't exist. Instead, there are only touch events. This isn't entirely true, because some devices on some browsers for some elements will simulate a mouse click when a touch is made.

How do I get a click event?

An element receives a click event when a pointing device button (such as a mouse's primary mouse button) is both pressed and released while the pointer is located inside the element.

How do I register an event in JavaScript?

The simplest way to register an event handler is by setting a property of the event target to the desired event handler function. By convention, event handler properties have names that consist of the word “on” followed by the event name: onclick , onchange , onload , onmouseover , and so on.

Can you remove event listener?

Event listeners can also be removed by passing an AbortSignal to an addEventListener() and then later calling abort() on the controller owning the signal.


3 Answers

If you are using jQuery than better use "bind" event to bind your click event.

For example:

    <div class="appLauncher" data-id= ' + i + '">
<img src="data:image/png;base64,' + base64 + '" alt="[~]" /><br /><span>' + label + '</span></div>

and than in javascript file you use:

$(".appLauncher").bind("click",function(){
   var i=$(this)attr("data-id");
   launchApp(i);
});

Try and let me know does it help you or not :)

like image 53
pixelbyaj Avatar answered Nov 10 '22 20:11

pixelbyaj


Not much of a javascript person, but I do know that Android makes a clear distinction between "one off" triggers and re-usable triggers (PendingIntents). Is it possible that you are somehow instantiating one off behavious of .appLaunch?

like image 44
Neil Townsend Avatar answered Nov 10 '22 19:11

Neil Townsend


I suppose you are hit by issue 19827

In this case, try adding a call to preventDefault (not tested)

$(".appLauncher").bind("click", function(e) {
   e.preventDefault();
   var i = $(this)attr("data-id");
   launchApp(i);
});
like image 2
rds Avatar answered Nov 10 '22 19:11

rds