Hi,

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);
}

2. In RemoteServiceBinding.java
  /**
     * This implementation is used to receive callbacks from the
remote
     * service.
     */
    private IRemoteServiceCallback mCallback = new
IRemoteServiceCallback.Stub() {
        /**
         * This is called by the remote service regularly to tell us
about
         * new values.  Note that IPC calls are dispatched through a
thread
         * pool running in each process, so the code executing here
will
         * NOT be running in our main thread like most other things --
so,
         * to update the UI, we need to use a Handler to hop over
there.
         */
        public void valueChanged(int value) {
                Log.d("ee", "valuechanged=" + value);
                mHandler.sendMessage(mHandler.obtainMessage(BUMP_MSG, value,
0));
        }

                                public void valueChangedList(List values) 
throws RemoteException {
                                        // TODO Auto-generated method stub
                                        Log.d("ee", "valuechangedlist=" + 
values.toString());
                                        
mHandler.sendMessage(mHandler.obtainMessage(LIST_MSG, values));
                                }

                                public void valueString(String value) throws 
RemoteException {
                                        Log.d("ee", "valueString=" + value);
                                }
    };


3. In RemoteService.java

   private final Handler mHandler = new Handler() {
        @Override public void handleMessage(Message msg) {
            switch (msg.what) {

                // It is time to bump the value!
                case REPORT_MSG: {
                    // Up it goes.
                    int value = ++mValue;

                    // Broadcast to all clients the new value.
                    final int N = mCallbacks.beginBroadcast();
                    for (int i=0; i<N; i++) {
                        try {
                            mCallbacks.getBroadcastItem(i).valueChanged
(value);
                                        List<String> values = new 
ArrayList<String>
();
                                        values.add("Hello, Mars");
                                        mCallbacks.getBroadcastItem
(i).valueChangedList(values);
                                        
mCallbacks.getBroadcastItem(i).valueString
("HEEELLLLOOOO");
                        } catch (RemoteException e) {
                            // The RemoteCallbackList will take care
of removing
                            // the dead object for us.
                        }
                    }
                    mCallbacks.finishBroadcast();

                    // Repeat every 1 second.
                    sendMessageDelayed(obtainMessage(REPORT_MSG),
1*1000);
                } break;
                default:
                    super.handleMessage(msg);
            }
        }
    };

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to