I would start by wrapping some of the C++ code in Java with JNI (you probably already have that).
AsyncTask isn't really appropriate, because it's a task, not a process, meaning it doesn't have a duration in time any more than necessary for one item of work. You can use Handler objects, they are not necessarily tied to the UI. You'd need two: one on the UI thread owned by the activity, one owned by the Java wrapper of the back-end thread, and associated with that thread. Take a look at HandlerThread, that's the basic idea for your backend, except you'd be calling a native method for processing messages. -- Kostya 2011/5/26 Oceanblue <[email protected]> > I have an interesting design challenge: > > I have a frontend(Activity) and a backend (written in native C/C++) > code. The backend is a complex object which partially controls the > flow of application & once started runs in it's own thread. So I have > a "distributed control" scenario. > > The Activity needs to be able to send messages asynchronously to the > backend which then takes certain actions. But the backend also needs > to be able to send messages asynchronously to the Activity, to which > it responds by chnaging UI, firing methods etc. > > Essentially what I need is a two-way listener. > > So backend sends a message to screen (take picture, prompt user, get > location, take another picture nowm etc) and screen does what it needs > to do. But in addition, the screen should also be able to call the > backend-listener to send back messages (captured camera image, system > generated - "I got paused/destroyed" message, etc) in the callbacks of > these events. Main problem is that this is all asynchronous. > > Is this possible without tight-coupling? Is this even possible? > > I have thought of Asynctask/handlers (but that's a one way street for > informing the UI thread), observer-pattern (both objects will be > observer/observable?) but confused on where to begin. Any thoughts, > links would be very helpful. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

