blob: cf8bd41935adbc61c7162eac9cd91d635db8d01e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
19import android.os.IBinder;
20
21/**
22 * Interface for monitoring the state of an application service. See
23 * {@link android.app.Service} and
24 * {@link Context#bindService Context.bindService()} for more information.
25 * <p>Like many callbacks from the system, the methods on this class are called
26 * from the main thread of your process.
27 */
28public interface ServiceConnection {
29 /**
30 * Called when a connection to the Service has been established, with
31 * the {@link android.os.IBinder} of the communication channel to the
32 * Service.
33 *
Kevin Hufnagled195a992017-06-29 15:58:48 -070034 * <p class="note"><b>Note:</b> If the system has started to bind your
35 * client app to a service, it's possible that your app will never receive
36 * this callback. Your app won't receive a callback if there's an issue with
37 * the service, such as the service crashing while being created.
38 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 * @param name The concrete component name of the service that has
40 * been connected.
41 *
42 * @param service The IBinder of the Service's communication channel,
43 * which you can now make calls on.
44 */
Dianne Hackborn94846032017-03-31 17:55:23 -070045 void onServiceConnected(ComponentName name, IBinder service);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046
47 /**
48 * Called when a connection to the Service has been lost. This typically
49 * happens when the process hosting the service has crashed or been killed.
50 * This does <em>not</em> remove the ServiceConnection itself -- this
51 * binding to the service will remain active, and you will receive a call
52 * to {@link #onServiceConnected} when the Service is next running.
53 *
54 * @param name The concrete component name of the service whose
55 * connection has been lost.
56 */
Dianne Hackborn94846032017-03-31 17:55:23 -070057 void onServiceDisconnected(ComponentName name);
58
59 /**
60 * Called when the binding to this connection is dead. This means the
61 * interface will never receive another connection. The application will
62 * need to unbind and rebind the connection to activate it again. This may
63 * happen, for example, if the application hosting the service it is bound to
64 * has been updated.
65 *
66 * @param name The concrete component name of the service whose
67 * connection is dead.
68 */
Dianne Hackbornac265342017-04-19 14:53:18 -070069 default void onBindingDied(ComponentName name) {
Dianne Hackborn94846032017-03-31 17:55:23 -070070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071}