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()

Android :: GPS Callback off UI Thread?


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 :: 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.

View 9 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 : Java - Implement A Run Method Of Thread If Create A Thread Global

Sep 7, 2010

How can I implement a run() method of thread if I create a Thread Global?

I mean If I create a Thread Globally then can I implement its run() method {" public void run()"} anywhere in my Application?

In the run() method I have to write the code to perform some action.

IF I can do it then please can anyone show me briefly how to do it particularly.

View 2 Replies View Related

Android : Handle Messages Between The Main Thread(the Deafult UI Related Thread) And The User Created Gamethread

May 21, 2009

I am writing an application in which i need to handle messages between the main thread(the deafult UI related thread) and the user created Gamethread.

The requirement is like this.

An activity(say "Activity_X") is setting the view by "setContentView(some "View_Y")". In "Activity_X" i have implemeted "onCreateOptionsMenu()" and "onOptionsItemSelected()" fucntions for creating menus & a switch case for action to be taken on selecting those menus.Menu has items like "resume/pause/zoom/" .

All action to be take on selecting these menus are implemented in "View_Y" in a separate Gamethread by extending "Thread" class.

So whenever a menu is selected in "Activity_X" i need to send a message to "View_Y". And on receiving this ,a particular action/method should be called in View_Y(GameThread).

How can i achieve this using Handlers?Is there any other way of doing this? Please do share with me some code snippets for these.

View 3 Replies View Related

Android :: Update ListView In Main Thread From Another Thread

May 27, 2010

I have a separate thread running to get data from the internet. After that, I would like to update the ListView in the main thread by calling adapter.notifyDataSetChanged(). But it does not work. Any workaround for that?

View 1 Replies View Related

Android :: Use Thread With SurfaceView - Ie Draw In Separate Thread?

Jul 22, 2009

I want to do the drawing in another thread to speed up the game(it is way to slow right now). I was told to do this but don't quite understand why that would speed things up. Is it GameView that should implement Runnable? Should I make the thread sleep when not drawing? where should I start the thread? package com.android.WWS;

import android.app.Activity; import android.content.Context; import android.graphics.*; import android.os.Bundle; import android.view.SurfaceView; import android.view.KeyEvent; import android.view.View; import android.view.View.OnKeyListener; import java.lang.Runnable; import java.lang.Thread;...................

View 4 Replies View Related

Android :: Suspend / Resume Thread From Another Thread In Same App

Feb 20, 2009

I need to suspend/resume a thread from another thread in the same process. I tried to look into thread apis,but I couldn't figured out a way to achieve this.Can anyone pls point me some references to look or give a tip to do this.

View 2 Replies View Related

Android :: Why Don't Get My OnContextItemSelected Callback

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

Android :: What Is A Binder Callback

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

HTC Droid Eris :: Remove Certain Texts From Thread In Easily Instead Of Whole Thread?

Dec 28, 2009

Does anyone know how to delete certain texts from a thread in an easy manner instead of having to delete a whole thread??

View 7 Replies View Related

Android :: Service Callback To Activity

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

Android :: Defining A Callback Function For A Given Value

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

Android :: Manage The Callback Of The Applications?

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

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 :: Camera Callback OnPreviewFrame?

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

Android :: OnSharedPreferenceChangeListener Never Receives Callback

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

Android :: ListView OnItemClickListener No Callback

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

Android :: Invalid Reference During Callback?

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

Android :: Callback URL Calling Oncreate

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

Android :: Main Thread The Same As UI Thread?

Jul 16, 2010

The Android doc says "Like activities and the other components, services run in the main thread of the application process." Is the main thread here the same thing as UI thread?

View 3 Replies View Related

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 :: How To Capture Browser Activity Or Callback

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

Android :: Starting An Activity From Callback Class

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

Android :: Callback To Activity After Layout Has Completed?

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

Android :: Network Service Need To Return Callback

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

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 :: Click Within WebView Causes Callback To Application

Feb 10, 2010

I'm thinking of implementing a HTML welcome panel to our Android app, which presents news and offers on the start-up screen. My question is now, if I present an offer to a specific place (with an id string) can I trigger a callback from the WebView (maybe via Java Script) to the Android app and passing that id string to make it start a new Activity which loads and shows data from a server (JSON) depending on that id string?

The second part is already implemented and working. My main concern is how to get the id string from the HTML WebView back to the Android app when the user clicks on it.

We prefer to use a WebView for that specific welcome panel, because it gives us more flexibility to customize by using HTML.

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







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