Office Hours — Today, April 30

Tuesday, April 28

Apr 30
8:50 AM
Mark M.
has entered the room
8:55 AM
Mark M.
turned on guest access
Yaniv S.
has entered the room
Mark M.
hello, Yaniv!
how can I help you today>
Yaniv S.
hello
Mark M.
er, today?
Yaniv S.
I talked to you some time ago about binding an app to a service
sort of like the "Servicing the service" example in your book
reminder:
I have a service that receives messages occasionally
and when a message is received I want the app to receive it
9:00 AM
Mark M.
IIRC, you had several apps
Yaniv S.
anyway Im using aidl and everything seems to be correct except that in the app
the onServiceConnected is never called
even though my onBind returns true
so the binding isn't really happening
View paste (43 more lines)
public class MainActivity extends Activity implements ServiceConnection  {
	public static final String TAG = "YANIV";
	private IExtMessage binding=null;
	private Message message;
	private Application appContext = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// TODO Auto-generated method stub
		super.onResume();
		Intent implicit=new Intent(IExtMessage.class.getName());
		List<ResolveInfo> matches=getPackageManager().queryIntentServices(implicit, 0);
		if(matches.size()==0){
...
this is the "app"
Mark M.
well, you are calling super.onResume() in onCreate(), which is unlikely to turn out well :-)
Yaniv S.
its not really an app just some activity i want to test this IPC
oh, oops.I didnt notice it. however I dont get any exception here
Mark M.
beyond that, are there any interesting messages in LogCat?
and, is onBind() being called?
Yaniv S.
yes it is called and returns true
Mark M.
onBind() cannot return true
onBind() is a method in your service
it returns a Binder
Yaniv S.
oh I thought you meant bindService()
no , onBind() is not called either
View paste (7 more lines)
public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		if (intent.getAction().equals("com.tfl.extprotocolservice.ISetIpPort")) {
			return (new IpPortBinder(getApplicationContext()));
		}
		if (intent.getAction().equals("com.tfl.extprotoclservice.IExtMessage")) {
			return new ExtMessageBinder();
		}
		return null;

	}

	//not used at the moment
	private class ExtMessageBinder extends IExtMessage.Stub {

...
this is my onBind
and these are my AIDL files, very simple :
View paste
package com.tfl.extprotocolservice;

interface ICallBackMessage{
void onMessageReceived(int command);
}
View paste
package com.tfl.extprotocolservice;
import com.tfl.extprotocolservice.ICallBackMessage;



interface IExtMessage{
	void getMessage(ICallBackMessage cb);
}
9:05 AM
Mark M.
can you paste in your <service> element for this service from your manifest?
Yaniv S.
View paste
        <service android:name=".ExtProtocolService" >
            <intent-filter>
                <action android:name="com.tfl.extprotocolservice.ISetIpPort" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.tfl.extprotocolservice.IExtMessage" />
            </intent-filter>
        </service>
Mark M.
hmmmm, OK, that seems fine
do any messages show up in LogCat when you try doing this binding?
sometimes, problems in background stuff like this wind up with warning severity, rather than error, for some reason
Yaniv S.
I honestly dont see any special messages
Mark M.
is onCreate() on your service being called?
Yaniv S.
yes , my service is working great in the background doing what it should be doing
9:10 AM
Mark M.
well, other than the super.onResume(), I do not see any other problems in what you have
Yaniv S.
Its weird because I have another app that binds to the service and it does work. just not full IPC , just sends the service a message
Mark M.
I honestly have not played with multiple apps binding to a service, but AFAIK, there is nothing you need to do special for that case
though I would make sure that your Binder object's public API is nicely asynchronous, so you release the binder thread it is called on in a timely fashion
you might also try starting from a clean slate (e.g., rebooting), then trying to use the app that is giving you problems *first*, before the working client
Yaniv S.
how do you mean?
Mark M.
if you look at my binding samples in the book, I fork a DownloadThread from the download() method on my Binder
now, technically, I don't have to do that, as download() is not going to be called on the main application thread
so I won't get an ANR or anything if I just do the download on the thread that I am called upon
however, we do not control the pool of "binder threads" used for IPC
and I have no idea if that pool grows
so, your Binder objects' methods should return quickly, to return the binder thread to the binder thread pool
which means if the Binder object wants to do more significant work (e.g., download a PDF), it should do so on its own separate background thread
9:15 AM
Mark M.
IOW, while the binder threads are not the main application thread, I recommend that you treat them as such, and spend as little time on them as possible
Yaniv S.
I have no binder thread here
Mark M.
yes, you do
all Intent-based IPC winds up using binder threads
you do not *explicitly* put stuff on that thread
Yaniv S.
oh ok
Mark M.
but, going back to my sample apps, my download() method will be called on a binder thread
at least in the remote-service, AIDL scenarios
(local services, it will be called on whatever thread calls the method)
Yaniv S.
just like my getMessage method
Mark M.
getMessage() and onMessageReceived() will be called on binder threads, yes
Yaniv S.
but where should I look for my problem
the client or the service?
Mark M.
I suggested earlier in the chat that you restart your test device, then try running the client that is giving you problems first, before running the client that is working
Yaniv S.
I am not even running the working client
Mark M.
if the client now works, then your problem is more that the *second* app cannot bind, and the problem would seem to be more on the service side
Yaniv S.
the working client only binds when I click a button in it's activity
9:20 AM
Yaniv S.
the not working one should bind as I run the activity
Mark M.
that's fine, but if it is still the same service process, perhaps something about doing that work in the working client is triggering the problem in the not-working client
Yaniv S.
so basically the working one is not really "colliding"
Mark M.
which is why I would recommend a clean test, to ensure that the working one is not part of the picture
I would even consider uninstalling the working client, to ensure it's not part of the mix
Yaniv S.
ok, I'll try that
Mark M.
if the problem recurs with solely the not-working client and the service, my guess is that the problem is on the client side, somehow
if the problem goes away, then that suggests that whoever tries using the service *second* has a problem, and that would suggest that the problem is on the service's side
Yaniv S.
and if the problem does go away how do I fix that in my service?
Mark M.
beats me
Yaniv S.
:)
Mark M.
sorry, but I am pretty much out of ideas right now
there's the super.onResume()
Yaniv S.
basically more than one app can bind to a service right?
Mark M.
AFAIK, yes, though I have never tried it
Yaniv S.
ok, I'll try
thanks Mark
Mark M.
sorry that I did not have a more concrete suggestion for you
Yaniv S.
no worries
9:25 AM
Yaniv S.
but if you happen to come up with a brilliant solution , could you mail me your idea?
Mark M.
coming up with a solution out of thin air is unlikely
Yaniv S.
ok:) thanks anyway . have a good day !
Mark M.
you too!
Yaniv S.
has left the room
9:45 AM
Yaniv S.
has entered the room
Mark M.
hello again!
Yaniv S.
hi again
so
I deleted the working client
and it works!
now my problem is somewhere in my service
right?
Mark M.
you mean the formerly-non-working client now works?
Yaniv S.
yep
onServiceConnected is now called
Mark M.
you might now try installing the formerly-working client and confirm that it stops working
if indeed it is no longer working, then the second client to talk to the service fails to do so, which suggests a problem on the service side
if the formerly-working client *still* works, then perhaps this was all a misunderstanding... :-)
Yaniv S.
I'll try, thanks again !
Yaniv S.
has left the room
10:00 AM
Mark M.
turned off guest access

Tuesday, April 28

 

Office Hours

People in this transcript

  • Mark Murphy
  • Yaniv Sheinfeld