Android :: OnItemClick Gets Called As Callback?
Dec 31, 2009
Could someone please shed the light as to where onItemClick() function gets called as callback when I click on the item of a ListView?
In core/java/android/widget/AdapterView.java:
onItemClick() belongs to the interface OnItemClickListener of AdapterView.
The listener is set through setOnItemClickListener() of AdapterView.
The listener is only invoked in performItemClick() of AdapterView.
The listener is also invoked indirectly in performItemClick() of ListView.
But, I still don't know where exactly onItemClick() of the listener will get called when I click on the item of a ListView. Logically it should be like:
device -> kernel driver -> dalvik VM -> my app.
Could someone please tell me the exact code that calls onItemClick() when I click on the item through the device?
In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices.
Join free software movement today! It is free as in freedom, not as in free beer!
Join: http://www.fsf.org/jf?referrer=4445
View 5 Replies
Feb 15, 2010
My Android Java Application needs to record audio data into the RAM and process it. This is why I use the class "AudioRecord" and not the "MediaRecorder" (records only to file).
Till now, I used a busy loop polling with "read()" for the audio data. this has been working so far, but it peggs the CPU too much. Between two polls, I put the thread to sleep to avoid 100% CPU usage. However, this is not really a clean solution, since the time of the sleep is not guaranteed and you must subtract a security time in order not to loose audio snippets. This is not CPU optimal. I need as many free CPU cycles as possible for a parallel running thread.
Now I implemented the recording using the "OnRecordPositionUpdateListener". This looks very promising and the right way to do it according the SDK Docs. Everything seems to work (opening the audio device, read()ing the data etc.) but the Listner is never called.
I am working with a real Device, not under the Emulator. The Recording using a Busy Loop basically works (however not satifiying). Only the Callback Listener is never called.
Here is a snippet from my Sourcecode:
CODE:.........................
View 2 Replies
View Related
Feb 12, 2009
I'm an experienced C++/Java dev who has been truly enjoying that past two days of getting neck deep into the Android SDK. I can foresee a lot of sleepless nights ahead Now, being arrogant due to experience (lol) I basically wrote a hello world Activity, got it to work and promptly decided to write an out of process service with accompanying client for project #2. Android is so well thought out (if not exactly documented although that's an 'over time' issue inmho) that I had basically implented everything but callbacks into the client before realizing (and feeling like a total idiot) that there's a very nice example called RemoteService (lol @ me - again) Basically, this validated everything I'd been doing, although I did notice that because my client is in its own project and namespace and my service is in another project and namespace (but the same Eclipse workspace) that I had to have the service entry in my service's manifest AND my client's manifest (that one took me a while to figure out) in order to bind on the service. Anyhow, everything's great, I am starting to love on Android (figuratively) but I've run into <BRITISH-NESS>a bit of a sticky wicket, eh, wot?</BRITISH-NESS>.
When my client Activity binds on my service (which is running in its own process) and calls the equivalent of 'registerCallback', the interface is added perfectly to the RemoteCallbackList object and I can immediately (right on the next line of code) use the interface to send a notification to the client. Now, my problem is that when my main service thread tries to pull the interface out of the RemoteCallbackList via the broadcast methods, the RemoteCallbackList is always 'empty' - it returns 0 from beginBroadcast. After double checking ensure that I AM actually adding it to the list (because I've been a collossal idiot before) and that I am getting success back from 'register', I immediately think it's a threading issue, so: I add logging code to the service in key places to log what the thread id is repeatedly, and I think "uh, I think I need to use a handler of some sort to make the call back in the thread that handled the registration" and to double check I call beginBroadcast right after 'register' and find that it always returns back the correct number of callback interfaces. So it VERY much appears to be a threading issue (to me) so now I'm a bit stuck I've written a handler so that my main service thread can request the correct thread to actually call 'beginBroadcast' and then thought 'how is it going to know what thread that is...?' and instead am now thinking I need to pass, via a handler or something, the incoming interface from the thread that runs when the client calls the equivalent of 'registerCallback' to my main service thread. What part of the proper paradigm am I missing? BTW, as an example of the thread IDs, my main service thread is #1, the runnable I use for tasks in the main service thread shows an ID of #1, the message handler I was thinking I could use, shows an ID of #1, but the thread ID I get in my code in the service that runs when the user registers their callback is #7.
If I plan to notify clients when the service notices something it thinks they need to know, do I need to notify (somehow) the clients via the thread with ID #7 or do I need to pass the interface I get when the user registers their callback from thread #7 to thread #1 and call 'register' on the RemoteCallbackList from thread #1? Sorry for the verbosity but I figured more is better than less. Again, everything works great except this one little part.
View 9 Replies
View Related
Feb 15, 2010
My Android Java Application needs to record audio data into the RAM and process it. This is why I use the class "AudioRecord" and not the "MediaRecorder" (records only to file).
Till now, I used a busy loop polling with "read()" for the audio data. this has been working so far, but it peggs the CPU too much. Between two polls, I put the thread to sleep to avoid 100% CPU usage.
However, this is not really a clean solution, since the time of the sleep is not guaranteed and you must subtract a security time in order not to loose audio snippets. This is not CPU optimal. I need as many free CPU cycles as possible for a parallel running thread.
Now I implemented the recording using the "OnRecordPositionUpdateListener". This looks very promising and the right way to do it according the SDK Docs. Everything seems to work (opening the audio device, read()ing the data etc.) but the Listner is never called.
I am working with a real Device, not under the Emulator. The Recording using a Busy Loop basically works (however not satifiying). Only the Callback Listener is never called.
Here is a snippet from my Sourcecode:
CODE:...............................
View 3 Replies
View Related
Aug 28, 2009
I'm trying to pop up an AlertDialog when someone long presses a list item.What I end up with is nested callback objects.I'm not sure if that is the problem but simple Alert dialog examples are not working for me.
View 3 Replies
View Related
Sep 2, 2010
I am confused with two below method
1.) onItemClick(AdapterView<?> arg0, View view, int position,long id) 2.) onListItemClick(ListView l, View v, int position, long id)
View 6 Replies
View Related
Sep 14, 2010
Been trying to find out what is the bookmark id the user clicked on...Tried everything, many force closes... and now an empty toast (no error marks in eclipse):
CODE:......
ImageCursorAdapter is another class showing bookmarks favicon and title (it works).
View 1 Replies
View Related
Jun 9, 2009
I want to use ListView each Item of wich has checkBox. I want checkBox check and uncheck when I click it and some processes runing when I click on item, but not on the checkBox. I'm trying to use this layout as item...
checkBox checks and unchecks as I want, but OnItemClickLictener doesn't catch anything when I click on Item. However it makes what I want if I choose and click it using trackball. What should I do?
View 2 Replies
View Related
Jan 21, 2010
I have a gridView that I display in a popupwindow (the gridview is in a transparent layout, which inherits from linearlayout and just has a partially transparent background). I can never get this GridView's OnItemClick to execute. When I touch an image in my gridview it appears to be clicked (image bachgrond changes), but OnItemClick is not being called.
Below is the code for my Adapter and my popupview containing the gridView.
CODE:................
View 2 Replies
View Related
Jun 3, 2010
I have a list view,each list item has a text view and a button. My onItemClick() for list item is not responding.But if i remove the button from list item it is responding.
View 3 Replies
View Related
Jun 3, 2009
I have code in my activity's onCreate that sets an onItemClick listener. when it fires I try to show a ProgressDialog that will be up until a subsequent thread "Thread" does it's processing. Strangely to me, the progress dialog never shows until *after* the thread.run() processing is complete. Almost like it's blocking. Am I doing something wrong? this is true even if the run method of doCurrentLocation doesn't do anything.
CODE:.................
View 3 Replies
View Related
Oct 26, 2010
I am running into an issue with the way my asynctasks are executed. Here's the problem code:
firstTask = new background().new FirstTask(context);
if(firstTask.execute().get().toString().equals("1"))
secondTask = new background().new SecondTask(context);
What I'm doing here is creating a new asynctask object, assigning it to firstTask and then executing it. I then want to fire off a separate asynctask when the first one is done and making sure it returns a success value (1 in this case). This works perfectly on Android 2.0 and up. However, I am testing with Android 1.5 and problems start popping up. The code above will run the first asynctask but doInBackground() is never called despite onPreExecute() being called. If I am to execute the first task without the get() method, doInBackground() is called and everything works as expected. Except now I do not have a way to determine if the first task completed successfully so that I can tell the second task to execute. Is it safe to assume that this is a bug with asynctask on Android 1.5? Especially since the API says that the get method has been implemented since API 3. Is there any way to fix this? Or another way to determine that the first task has finished?
View 2 Replies
View Related
Aug 28, 2010
I am implementing a context menu for my main activity.
I have some XML to define the items:
CODE:...............
I have this code to create the menu:
CODE:.................
When I click the menu button, my context menu appears with the appropriate items and icons. When I select a menu item, I don't get the callback.
View 1 Replies
View Related
Jul 6, 2010
I'm having trouble getting the GPS's onLocationChanged to run on a different thread. I understand how to manage UI thread when I'm calling a function but with the GPS, I don't actively call the function.
My intent is to have a light flash every time the GPS receives a reading. I have put this function in a Runnable. I passed this function to a class that implements LocationListener. Then in the main class, I started a new thread that calls requestLocationUpdates. I was hoping that onLocationChanged of the LocationListener would run in a different thread, post to the callback and make the necessary UI effects in the UI thread. Unfortunately, the program crashes every time it tries to call requestLocationUpdates. What's the proper way of doing it?
Right now it looks something like this
Main class:
CODE:................
LocationListener class:
CODE:...............
The exception says Can't create handler inside thread that has not called Looper.prepare()
View 3 Replies
View Related
Aug 31, 2010
I have been watching the Google I/O presentation by Virgil Dobjanschi on the correct way to implement REST on Android with services and content providers. http://code.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html
Based on the video I'm doing things the wrong way, which is not surprising given how hard the right way is. Anyway, having been shown the promised land in the video I'm having a bit of a problem figuring out how to get there.
I have most of it nailed but the one thing that's defeating me is the Binder Callback that Virgil references in the slides (see link above), on page 43 it shows step 2 as starting the service with startService( intent ) and step 10 as returning status information using a Binder Callback. There is no example code anywhere in the presentation which is rather frustrating. There is talk of open sourcing the Twitter client which apparently uses this approach but nothing yet and the announcement was in April.
In the video he states: "What is a binder callback? A binder callback, think of it as an interface that was passed in the request intent."
I have searched all over the place but have not been able to find any doc or examples that show how to pass a callback as part of an intent. Nor can I figure out any other way of passing in a callback.
I thought he may be referring to binding to the service and implementing the callback that way. However, he is specifically referring to a local service and using strarSerice() and not bindService(). Also with bindService() the service will be destroyed if the activity is destroyed which defeats the idea. The workaround is to use startService() and then bindService() and leave the service running for the duration. The other problem with bindService() is that the callback can not be use until onServiceConnected() completes which complicates the code even further as the action instructions can not be passed in the intent because the return callback may not be in place in time to return the results.
View 1 Replies
View Related
Jan 13, 2010
Our application will expose a Service that can be called by Activities in other people's applications.In many cases, the parent applications calling Activity may be paused before our Service completes. I am looking for the best way for a Service to communicate back to the calling Activity that may have been paused.These are the known options:
(1) Require calling Activities to have a registerReceiver() with a custom action and broadcast to that from our Service. The only way to secure this registerReceiver() is with a signature-based permission.As our Service communicates with any number of unknown 3rd party apps,we can't sign our Service's parent app with all these unknown certificates. These apps would therefore be exposing an unsecured registerReceiver() on their Activity. Would ideally like to avoid requiring this.
(2) Create a PendingIntent to send results back to the activity and give it to our Service. Our Service would send data to calling Activity's onActivityResult(). Each time the result is delivered, the calling Activity will go through onPause() and onResume() but this should be OK.
(3) The calling Activities could create a Handler. The Activity would then create a Messenger pointing to that Handler and send it to our service. Our Service can then use the Messenger to deliver our message back to the calling Activity.
View 2 Replies
View Related
Sep 13, 2010
In Java, is it possible to associate some object (i.e. a String) with a function to be called ? I have two similar menus and both have a onClickListener with some code like this: Code...
View 4 Replies
View Related
Apr 2, 2010
in android application development, i frequently go through the word "CALLBACK" in many places. i want to know want it means to tell us technically. and how i can manage the callback of the applications.
View 2 Replies
View Related
Nov 10, 2010
I am working on an application in Android and I have to manipulate the data coming from the preview.
I read that the default frame rate is 15fps. I measured the time from one call of the onPreviewFrame function and the next one and I noticed that I got different times depending on the size of the preview (at the moment no other operations are done in this function). How can it be possible? I thought it would be called at any frame so 15 times in a second (approximately every 66ms) independently of the previewFrameSize.
View 2 Replies
View Related
Jun 15, 2010
I'm trying to listen for preference changes from an activity (see below). It never fires. Is it due to the fact that the activity in question is not in focus when the change event fires?
CODE:.....................
View 10 Replies
View Related
Jun 3, 2009
Hi, One of my ListView's has a CheckBox on every item's RelativeLayout.
I just found that clicking on any item of the ListView does not callback its OnItemClick().
If I remove the CheckBox from item layout, callback is ok then.
My app needs to get both callbacks from the CheckBox as well as from "the other area" of a ListView item.
I read http://android-developers.blogspot.com/2008/12/touch-mode.html But I'm a bit confuse.
How I get the callback on the ListView with CheckBox?
CODE:..................
View 7 Replies
View Related
May 4, 2010
I'm trying to create a simple multiplayer game. There's a WorkerService which is supposed to handle all network communication and all interaction between this service and my Activities is done with AIDL. I think this is a standard approach - to enable two way interaction I use also an IWorkerCallback interface (also AIDL).
The problem is that callbacks have to change things in UI which may be done only in UI thread. I've created a Handler (in UI thread) and believed that this is an obvious solution. But, surprisingly, it's not working.
My LoungeActivity calls startServer() method of IWorker interface. Corresponding method of my WorkerService does some job and makes a callback - this works fine. Then WorkerService spawns a new thread and callback from this thread results in a bad Exception being thrown:
Can't create handler inside thread that has not called Looper.prepare()
Here's some code to make it clear:
CODE:............
ServerThread code:
CODE:................
Every method from callback looks like that:
CODE:.................
In Handler's handleMessage() method I'm doing a simple switch(msg.what) and in every case there's a simple UI modification (showing a Toast, changing Text, etc.)
I have no idea why is this Exception thrown.. I've managed to fix it by packing code into a Runnable and calling runOnUiThread() but it still makes me curious - shouldn't a Handler always run in thread that created it?
View 2 Replies
View Related
Jul 29, 2010
I have an object that is used for calling callback functions ----- static jobject o;
I have assigned the callback function to that object through a pointer, env -----
o=env->NewGlobalRef(callback);
The same pointer, env, points towards the function CallVoidMethod( ) that uses JNI to reach to the java code.
env->CallVoidMethod(o, methodId, pDeviceId, deviceStatus, statusReason, connectionProgressInfo);
However on calling this function, the system is getting crashed, and VM says that it's an invalid reference to static jobject o and then it crashes.
My code is as follows :
CODE:..........................
View 2 Replies
View Related
Jul 30, 2010
I am making twitter application in which i open browser for user authentication and i pass call_back URL when launching authentication browser.
Problem is after authenticating it is calling again oncreate of TWitterShare class instead calling onNewIntent method, why is that ? my another class working fine i am unable to find difference any idea by looking at the following ocde why it is calling oncreate again ?
CODE:...................
View 2 Replies
View Related
Mar 5, 2010
I was trying to find out were my apps memory was being leaked and was able to discover that when calling registerCallback(...) it would lead to a memory leak after a screen orientation change. What could be some possible things that are causing the leak? I've tried many things. And I do have a unregisterCallback(..) call.
View 20 Replies
View Related
Sep 14, 2009
My activity calls a browser activity where the users submits their info to retrieve a PIN. That PIN is then sent as a parameter to a url specified in the request.
View 4 Replies
View Related
Aug 18, 2010
I have an activity class(Application Class ) which calls a service class(Service Class) and closes. The service class takes about 5 seconds to complete its task and calls a method which is present in another class(Callback Class). Now according to the result, the callback needs to notify the Application class.Once i get the callback from the service, I tried calling a method defined in the Application class. In this method i create a new intent of Application class and call startActivity(Application Class). But this is not working. Can anyone tell where i am going wrong and what can I do to solve this issue.
View 5 Replies
View Related
Jun 3, 2009
I want to find the dimensions of the various views in my layout. My understanding is this can only be done after layout is completed since layout is somewhat dynamic. So, after the activity calls setContentView() and then returns control on the main thread to the OS so that layout can occur, how do I get a notification that layout has completed so I that I can query the views for their dimensions? On a related topic, can I find out the status bar's height or least the screen's full size (from which the status bar's height can be calculate by subtracting my window's height)?
View 2 Replies
View Related
Oct 6, 2010
if the service dies, and i know it can during request processing, it's an issue for me, first i've seen it, the process wont die until the net request returns (then the thread dies gracefully), unless kill -9 is used on the process... then i'm not sure what android does with the connections. I'm not sure what's the approach i should take here.(it will be true though even if this was a local thread and not a service)if i want the service to listen on a callback and call it once the network processing is done, i'm in a problem, no instances can be passed on using Intents.
So i need some other solutions, all the ones i though of sounds bad to me: A. use IBinder to get instance of the network service class then i can call one of it's methods and pass on an instance, this will work since they all run in the same process, BUT requires me to use Async way to get a Network instance which is not so suitable for me. B. Use static member in the Service i can access, then what to i need the service for ?. use intent to send parameters only to the service, the service will compose a Request out of it and put it in the queue, then once done will send a response using intent which will encapsulate the response (which might be long!) and will also contain the name of the calling class as a string so all the Receivers will know if it's for them or not - BIG overhead of encapsulating data in Intent and search in all the receivers for the right one to get the response.I don't want to use the service as a local running simple thread since i'm afraid if i'll run it in the root activity i will have to use static container so it will be visible in each activity and if the root will be destroyed for some reason it will take all the service with it, even if i start new task and the process is still alive.Anyone got some nice ideas on how to approach this thing ?
View 1 Replies
View Related
Feb 1, 2009
I have a ListView that is populated with a custom adapter. When an item is clicked with the trackball, it works fine, i.e. I can catch the event and move on, though when I touch an item with my finger there is no callback from the listener.The item does respond to the touch, by turning orange for that moment.What am I missing? Is there another listener I need to configure?
View 11 Replies
View Related