1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package io.flutter.embedding.engine.plugins.activity; 6 7 import android.support.annotation.NonNull; 8 9 /** 10 * {@link FlutterPlugin} that is interested in {@link Activity} lifecycle events related to a 11 * {@link FlutterEngine} running within the given {@link Activity}. 12 */ 13 public interface ActivityAware { 14 /** 15 * This {@code ActivityAware} {@link FlutterPlugin} is now associated with an {@link Activity}. 16 * <p> 17 * This method can be invoked in 1 of 2 situations: 18 * <ul> 19 * <li>This {@code ActivityAware} {@link FlutterPlugin} was just added to a {@link FlutterEngine} 20 * that was already connected to a running {@link Activity}.</li> 21 * <li>This {@code ActivityAware} {@link FlutterPlugin} was already added to a 22 * {@link FlutterEngine} and that {@link FlutterEngine} was just connected to an 23 * {@link Activity}.</li> 24 * </ul> 25 * The given {@link ActivityPluginBinding} contains {@link Activity}-related references that an 26 * {@code ActivityAware} {@link FlutterPlugin} may require, such as a reference to the actual 27 * {@link Activity} in question. The {@link ActivityPluginBinding} may be referenced until either 28 * {@link #onDetachedFromActivityForConfigChanges()} or {@link #onDetachedFromActivity()} is 29 * invoked. At the conclusion of either of those methods, the binding is no longer valid. Clear 30 * any references to the binding or its resources, and do not invoke any further methods on the 31 * binding or its resources. 32 */ onAttachedToActivity(@onNull ActivityPluginBinding binding)33 void onAttachedToActivity(@NonNull ActivityPluginBinding binding); 34 35 /** 36 * The {@link Activity} that was attached and made available in 37 * {@link #onAttachedToActivity(ActivityPluginBinding)} has been detached from this 38 * {@code ActivityAware}'s {@link FlutterEngine} for the purpose of processing a configuration 39 * change. 40 * <p> 41 * By the end of this method, the {@link Activity} that was made available in 42 * {@link #onAttachedToActivity(ActivityPluginBinding)} is no longer valid. Any references to the 43 * associated {@link Activity} or {@link ActivityPluginBinding} should be cleared. 44 * <p> 45 * This method should be quickly followed by 46 * {@link #onReattachedToActivityForConfigChanges(ActivityPluginBinding)}, which signifies that a 47 * new {@link Activity} has been created with the new configuration options. That method provides 48 * a new {@link ActivityPluginBinding}, which references the newly created and associated 49 * {@link Activity}. 50 */ onDetachedFromActivityForConfigChanges()51 void onDetachedFromActivityForConfigChanges(); 52 53 /** 54 * This plugin and its {@link FlutterEngine} have been re-attached to an {@link Activity} after 55 * the {@link Activity} was recreated to handle configuration changes. 56 * <p> 57 * {@code binding} includes a reference to the new instance of the {@link Activity}. {@code binding} 58 * and its references may be cached and used from now until either 59 * {@link #onDetachedFromActivityForConfigChanges()} or {@link #onDetachedFromActivity()} is 60 * invoked. At the conclusion of either of those methods, the binding is no longer valid. Clear 61 * any references to the binding or its resources, and do not invoke any further methods on the 62 * binding or its resources. 63 */ onReattachedToActivityForConfigChanges(@onNull ActivityPluginBinding binding)64 void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding); 65 66 /** 67 * This plugin has been detached from an {@link Activity}. 68 * <p> 69 * Detachment can occur for a number of reasons. 70 * <ul> 71 * <li>The app is no longer visible and the {@link Activity} instance has been destroyed.</li> 72 * <li>The {@link FlutterEngine} that this plugin is connected to has been detached from 73 * its {@link FlutterView}.</li> 74 * <li>This {@code ActivityAware} plugin has been removed from its {@link FlutterEngine}.</li> 75 * </ul> 76 * By the end of this method, the {@link Activity} that was made available in 77 * {@link #onAttachedToActivity(ActivityPluginBinding)} is no longer valid. Any references to the 78 * associated {@link Activity} or {@link ActivityPluginBinding} should be cleared. 79 */ onDetachedFromActivity()80 void onDetachedFromActivity(); 81 } 82