On Nov 2, 10:53 am, Mark Murphy <[email protected]> wrote:
> Um, I'll be surprised if what you propose here is stable. I don't
> think out parameters are designed for long-term use, just for a single
> call (which is equivalent to returning the value). The primary
> advantage of out parameters is that you can have more than one.
>
> If you want to implement a callback, then you should implement a callback:
>
> -- define an AIDL interface for the callback
> -- have your method take an instance of that callback as a regular
> (in) parameter
> -- create a .Stub implementation of the callback in the client and
> supply an instance of it when calling the service's exposed method
> -- the service receives the proxy as the parameter to its method
> implementation and can use that as needed
>
> The RemoteClientEx and RemoteServiceEx examples in this directory
> demonstrate this:
>
> https://github.com/commonsguy/cw-advandroid/tree/master/AdvServices
Thanks for the detailed response!
My original post doesn't contain enough context as this is a larger
issue, so I'll fill in the details now. Would it horrify you to know
that the link you provided is what I was using as a reference when I
started walking down this road? ;) Full disclosure: This is my first
Android app; I come from an iPhone background, so this is all very new
to me.
I have the following:
1. IGameInterface.aidl - This is the equivalent of IScript.aidl in the
sample code. It has one method: void doStuff(IGameInterfaceResult
callback).
2. IGameInterfaceResult.aidl - This is where the definition of the
interface for the callback goes. As in my original post, it has one
method: void success(Bundle).
3. GameService.java - Ignoring the poor naming convention for a
moment, this is a subclass of Service and functions as BshService.java
does in the sample code. It contains code like the following:
public class GameService extends Service {
private final IGameInterface.Stub binder = new IGameInterface.Stub()
{
public void doStuff(final IGameInterfaceResult callback) {
Bundle coolStuff = makeCoolStuff();
callback.success(coolStuff);
}
};
}
My (admittedly weak) understanding is that this is okay. Given the
extra context, does this still sound unstable to you?
> Making the change you've suggested wouldn't work in this
>
>
>
>
>
>
>
>
>
> > case. That said, if you've got a suggestion for a different approach
> > to this problem I'd love to hear it.
>
> > On Nov 2, 4:42 am, Mark Murphy <[email protected]> wrote:
> >> Try switching to:
>
> >> Map success();
>
> >> It may be that Map does not support out properly. I have never used
> >> the out keyword in AIDL, as it leads to scary programming (relying on
> >> side-effects applied to parameters).
>
> >> On Mon, Oct 31, 2011 at 9:52 PM, randyv2 <[email protected]> wrote:
> >> > I have an AIDL written as follows:
>
> >> > interface IGameInterfaceResult {
> >> > void success(out Map result);
> >> > }
>
> >> > In the generated .java file, I see this being generated:
>
> >> > _arg0 = new java.util.Map();
>
> >> > This leads to my project having errors because Map can't be
> >> > instantiated. This seems like a bug in the AIDL tool, but my googling
> >> > hasn't resulted in anything useful regarding this error. Does anybody
> >> > have suggestions on what I should try doing to resolve this problem?
>
> >> > --
> >> > 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
>
> >> --
> >> Mark Murphy (a Commons
> >> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> >> _Android Programming Tutorials_ Version 4.0 Available!
>
> > --
> > 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
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> _Android Programming Tutorials_ Version 4.0 Available!
--
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