Android :: Remote Callback List Register Called On One Thread Broadcast Initiated

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.

Android :: Remote Callback List register called on one thread broadcast initiated


Android :: Register Callback Leaks Memory?

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

Android :: Register Get / Set Hooking Callback Function At Class

Apr 7, 2010

I release a class. In the class, there are public fields that can be written. I want to register the callback function which will be called right after my field is accessed. I think I can do that by using JVM tool interface which is supposed to be used for a debugger software. JVM tool interface:

I'm not sure same interface is working on android. or, They provide another form of interface to get a notification of a field access.

View 2 Replies View Related

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 View Related

Android :: AudioRecord Class - Callback Is Never Called

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

Android :: GPS Callback Off UI Thread?

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

Android :: Callback From Another Thread Causes An Exception

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

Android :: To Unregister A Broadcast Receiver Register Registered In Manifest File

Mar 19, 2010

I have been able to register and unregister a broadcast receiver from the java code and know that a broadcast receiver is unregistered (even if it is not done explicitly) on its own as the process that registered it is killed. Now I have a broadcast receiver which has been registered through manifest file and not through the java code, and need to unregister the broadcast receiver from the java code. Since this, i think would need a reference to System context that instantiates the broadcast receiver.

View 4 Replies View Related

Android :: Register To Remote Server On First Application Uses

May 5, 2010

I am writing a android application where I want to register my application to remoter server when application is first launched on installation. Application will register to remoter server itself without taking any user input. How Can I track whether this is a first application launch after installation?

View 1 Replies View Related

Android :: Broadcast Receiver Not Getting Called When Expected

Dec 27, 2009

I have a service that gets updated every x minutes depending on the user preferences. This service connects to a web service and pulls some data. If during an update the user has no connection I register my receiver and start listening for changes (ConnectivityManager.CONNECTIVITY_ACTION), the thing is that onReceive () only gets called on every update instead of firing onReceived as soon as I plug the connection back in. Have I understood the concept of Broadcast Receiver wrong? Is it not suppose to send a notification as soon as it detetcs a change in the connection?

View 4 Replies View Related

Android :: Broadcast Receiver - Alarmservice Never Called

Jul 3, 2009

I've been modifying things All day trying to get this to work. I have a broadcast receiver that receives a "boot completed" signal. the onReceive method works! Well at least it sends output to the log. The problem is that that method is responsible for creating a AlarmService, to start call a different class every minute. That other class never has it's onReceive method called...

AndroidManifest snippet: <receiver android:name=".FmiBootup">
<!-------------THIS WORKS FINE------------->
<intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /

View 6 Replies View Related

Android :: Android: AudioRecord Class - Callback Is Never Called

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

Android :: Register Receiver For Events In Separate Thread

Aug 14, 2009

I want a separate thread from a service to register a receiver for wifi events. However as I need a context for doing that (and I'm using service one) I'm receiving the intents on the main thread. Is there any possibility to register a receiver for executing in other thread than main?

View 2 Replies View Related

Android :: Broadcast Receiver And Remote Service

Jan 20, 2010

I'm hoping to do some audio processing in a remote service (service I've spawned onto its own thread); this will basically occur in a while (1) loop so constant processing. Occasionally I want to provide some information back to the activity that is bound to the service; I'm doing this by sending a broadcast from the service, that is received by a broadcast receiver on the activity, which then uses the activity's service connection to call into the service and get the information needed; at this point the broadcast receiver makes an alert dialog presenting the information to the user.If I stay in my while(1) loop after raising the broadcast, the action in the broadcast receiver never seems to occur.This is confusing to me since the activity and service are in separate threads.If I end the loop after raising the broadcast, the desired behavior on the activity side occurs, but of course this isn't acceptable since I need to be doing constant processing.

View 11 Replies View Related

Android :: No Callback When List Item Is Touched

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

Android :: Broadcast Receiver / Service & Thread

Jun 23, 2010

I am starting to develop a new app and I am a bit confused about the structure I need to give it.I need to react to broadcast intents, so I placed a broadcast received in the manifest. Every single intent produces an action to be performed. Now the first question: should I start a service (maybe with non_sticky option?) or should I start a thread (or an async task) directly from the broadcast receiver? If I start a service, should I do all the stuff in its body, or should it start a thread. I should do the heavy job in a thread if there are time consuming operations, but what if the gui of my application is just an activity with the options and a button to start the service. What is the point in keeping the main thread busy? Do I risk to be killed for not being responsive? I read here and there that I can update the gui from a background thread. Can I do that even if it is started from a service? The AsyncTask's onProgressUpdate is said to run in the application main thread, but if the application is made of different activities, who tells me which activity is the user looking at while the thread is doing all its long work? The user could change activity in the meanwhile and then the update would be unuseful.I know it's (quite) a lot of questions, but I need to get some clarifications before taking the wrong path.

View 5 Replies View Related

Android :: How To Identify Which Client Called Into A Remote/AIDL Service

Jul 26, 2010

In the implementation of my remote service's published API, is there a way to identify which client called a given method? For example, is there a way to obtain a unique ID or address of the caller? I already cache an AIDL callback reference to the client, but not sure how I can use this for identification.

View 4 Replies View Related

Android :: AudioTrack Start Called From Thread

Dec 8, 2009

I am getting the 'AudioTrack::start called from thread' when starting an AudioTrack. I am using it in a thread. I asume I shouldn't but why? I see it as a major limitation.

View 4 Replies View Related

Android :: What Happens To Thread As On Destroy Is Called When Device Is Rotated

Jun 15, 2010

I would like to know as to what will happen to the thread which has been created by an activity and the device is rotated. I have observed that the onDestroy method is called when this happens. Will the thread be killed too?If the thread is not killed, how can I reassociate the thread with the activity as a new instance of the activity is created on rotation.

View 1 Replies View Related

Android :: Making Broadcast Receiver Post Of UI / Main Thread

Jun 10, 2010

Are we guaranteed that Application.onCreate() runs in the UI/main thread? I want to assume so but I can't find any information to make me 100 % sure. When I receive a broadcast I want to post a message onto the UI/main thread. Currently I've added a function in my Application class to return a handler (created in it's onCreate), is this a good solution? If not, what would be a better solution?

View 3 Replies View Related

Android :: Run Query On Background Thread On Cursoradapter Doesn't Get Called?

Jul 25, 2010

I have a listactivity as a startup screen in my application. Which is displaying database records using custom cursor adapter. On create I set the filterable flag - getListView().setTextFilterEnabled(true)

My cursoradapter overrides runQueryOnBackgroundThread which runs corresponding query. The problem is that after typing some text and hitting enter, runQueryOnBackgroundThread never gets called. However, when the item click in the same view launches another activity(detail view of the record) and I come back to the original list activity, hitting back button, then text filtering works just fine. I don't call setTextFilterEnabled anywhere except during the initialization process and I can't really find any other API affecting this behavior, so any guesses why text filtering doesn't work initially, but all of the sudden starts working when I come back to the list activity from child activity?

View 3 Replies View Related

Android :: OpenGL Thread Suddenly Dead? (on Draw Frame No More Called)

Mar 22, 2010

I have a problem with a suddenly dead(?) OpenGL Thread. After an indeterminate time (30 seconds to a couple of minutes) the onDrawFrame of the Renderer simply doesn't get called anymore. I get no exception, no ForceClose, no ActivityNotResponding, no nothing! I can still open the Menu, have another Handler/Runnable-cycle logging out "Alive", etc Recently I introduced some native stuff (physics-library). But I can verify that there is no native problem, as there is obviously no native crash and after the GLThread died, I can still do like: Log.d("Before native call") nativeCall(); Log.d("After native call") Maybe anyone of you experienced something similar to this?

View 4 Replies View Related

Android :: Can't Create Handler Inside Thread That Has Not Called Looper.prepare

Oct 6, 2010

What does the following exception mean? And how can I fix it?
This is the code:Toast toast = Toast.makeText(mContext, 'Somthing', Toast.LENGTH_SHORT);
This is the exception:
D/VVM ( 684): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
D/VVM ( 684): at android.os.Handler.(Handler.java:121)
D/VVM ( 684): at android.widget.Toast.(Toast.java:68)
D/VVM ( 684): at android.widget.Toast.makeText(Toast.java:231)

View 1 Replies View Related

Android :: Http Post Abort Not Returning Immediately When Called From Separate Thread

Mar 24, 2010

I am using a DefaultHttpClient and a ThreadSafeClientConnManager to share the httpClient across threads. That part is working well. However, when I execute an HttpPost in one thread, and call httpPost.abort() from another. It does not return immediately and continues blocking until the socket timeout is reached in most cases. Am I missing something else? I've tried using: connectionManager.closeIdleConnections(30, TimeUnit.SECONDS); connectionManager.closeExpiredConnections();

View 2 Replies View Related

Android :: Dialog Callback From Withing Callback?

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

Android :: List Of All Calendar Broadcast Intents?

Jun 9, 2009

I'm trying to capture when a calendar reminder goes off. What I'm trying to do right now is use a BroadcastReceiver and receive an intent from the calendar. Is there an intent that gets broadcast when a calendar reminder goes off? If so what is its name, or where can I find it? Is there a list of all the calendar intents somewhere?

View 3 Replies View Related

Android :: Android - Can't Handler Inside Thread Not Called Looper Prepare

Sep 30, 2010

I am getting reports of 'Can't create handler inside thread that has not called Looper.prepare()' once I added ScoreNinja to my Android app, and released it to the market. It seems that it isn't happening all the time as the ScoreNinja highscore has lots of entries from users. I have looked on the web for help but there are no clear directions on what to do. I have used the ScoreNinja code exactly as shown on the scoreninja website. BTW If anyone is having problems with ScoreNinja only displaying one score, check to see if the launchmode is not set to 'singleinstance' in your manifest. This fixed it for me!

View 6 Replies View Related

Android :: Retrieving List Type From Remote Service

Aug 15, 2009

I am having trouble passing a List type from a remote service to the UI activity. Here is a modified version of RemoteService example from the APIDemo. (only included where its modified)

PROBLEM: The call back function (for List) is called successfully, but the List returned is empty...

It works fine when the service does not run in a remote process. (w/o android:process=":remote" in the manifest file)

Why is this happening...?

Also, when I tried Map type, it didn't even successfully generate a IRemoteServiceCallback.java file.... it tries to do new Map().... and complains that its an abstract class.. (FYI, List instantiates by new ArrayList())

1. in IRemoteServiceCallback.java oneway interface IRemoteServiceCallback { /*** Called when the service has a new value for you. */void valueChanged(int value); void valueChangedList(out List values); void valueString(String value);}

View 2 Replies View Related

Samsung I7500 :: Removing Frequently Called Numbers From List?

May 8, 2010

How do I remove frequently called numbers from the list? Its really annoying and not accurate. People who have called once also appear.

View 6 Replies View Related

Motorola Droid :: Removing Frequently Called Numbers From Contact List

Nov 11, 2009

In my contact list after the listing of "favorites" is a listing of "frequently called numbers" How do I remove numbers from that list?

View 45 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved