The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.content; |
| 18 | |
| 19 | import 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 | */ |
| 28 | public 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 | * |
| 34 | * @param name The concrete component name of the service that has |
| 35 | * been connected. |
| 36 | * |
| 37 | * @param service The IBinder of the Service's communication channel, |
| 38 | * which you can now make calls on. |
| 39 | */ |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 40 | void onServiceConnected(ComponentName name, IBinder service); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Called when a connection to the Service has been lost. This typically |
| 44 | * happens when the process hosting the service has crashed or been killed. |
| 45 | * This does <em>not</em> remove the ServiceConnection itself -- this |
| 46 | * binding to the service will remain active, and you will receive a call |
| 47 | * to {@link #onServiceConnected} when the Service is next running. |
| 48 | * |
| 49 | * @param name The concrete component name of the service whose |
| 50 | * connection has been lost. |
| 51 | */ |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 52 | void onServiceDisconnected(ComponentName name); |
| 53 | |
| 54 | /** |
| 55 | * Called when the binding to this connection is dead. This means the |
| 56 | * interface will never receive another connection. The application will |
| 57 | * need to unbind and rebind the connection to activate it again. This may |
| 58 | * happen, for example, if the application hosting the service it is bound to |
| 59 | * has been updated. |
| 60 | * |
| 61 | * @param name The concrete component name of the service whose |
| 62 | * connection is dead. |
| 63 | */ |
Dianne Hackborn | ac26534 | 2017-04-19 14:53:18 -0700 | [diff] [blame] | 64 | default void onBindingDied(ComponentName name) { |
Dianne Hackborn | 9484603 | 2017-03-31 17:55:23 -0700 | [diff] [blame] | 65 | } |
Christopher Tate | 5d73b6d | 2017-10-06 16:15:34 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Called when the service being bound has returned {@code null} from its |
| 69 | * {@link android.app.Service#onBind(Intent) onBind()} method. This indicates |
| 70 | * that the attempting service binding represented by this ServiceConnection |
| 71 | * will never become usable. |
| 72 | * |
| 73 | * <p class="note">The app which requested the binding must still call |
| 74 | * {@link Context#unbindService(ServiceConnection)} to release the tracking |
| 75 | * resources associated with this ServiceConnection even if this callback was |
| 76 | * invoked following {@link Context#bindService Context.bindService() bindService()}. |
| 77 | * |
| 78 | * @param name The concrete component name of the service whose binding |
| 79 | * has been rejected by the Service implementation. |
| 80 | */ |
| 81 | default void onNullBinding(ComponentName name) { |
| 82 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | } |