Flutter Engine
The Flutter Engine
FlutterActivity.java
Go to the documentation of this file.
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
5package io.flutter.app;
6
7import android.app.Activity;
8import android.content.Context;
9import android.content.Intent;
10import android.content.res.Configuration;
11import android.os.Bundle;
12import androidx.annotation.NonNull;
13import io.flutter.app.FlutterActivityDelegate.ViewFactory;
14import io.flutter.plugin.common.PluginRegistry;
15import io.flutter.view.FlutterNativeView;
16import io.flutter.view.FlutterView;
17
18/**
19 * Deprecated base class for activities that use Flutter.
20 *
21 * @deprecated {@link io.flutter.embedding.android.FlutterActivity} is the new API that now replaces
22 * this class. See https://flutter.dev/go/android-project-migration for more migration details.
23 */
24@Deprecated
25public class FlutterActivity extends Activity
26 implements FlutterView.Provider, PluginRegistry, ViewFactory {
27 private static final String TAG = "FlutterActivity";
28
29 private final FlutterActivityDelegate delegate = new FlutterActivityDelegate(this, this);
30
31 // These aliases ensure that the methods we forward to the delegate adhere
32 // to relevant interfaces versus just existing in FlutterActivityDelegate.
33 private final FlutterActivityEvents eventDelegate = delegate;
34 private final FlutterView.Provider viewProvider = delegate;
35 private final PluginRegistry pluginRegistry = delegate;
36
37 /**
38 * Returns the Flutter view used by this activity; will be null before {@link #onCreate(Bundle)}
39 * is called.
40 */
41 @Override
43 return viewProvider.getFlutterView();
44 }
45
46 /**
47 * Hook for subclasses to customize the creation of the {@code FlutterView}.
48 *
49 * <p>The default implementation returns {@code null}, which will cause the activity to use a
50 * newly instantiated full-screen view.
51 */
52 @Override
53 public FlutterView createFlutterView(Context context) {
54 return null;
55 }
56
57 /**
58 * Hook for subclasses to customize the creation of the {@code FlutterNativeView}.
59 *
60 * <p>The default implementation returns {@code null}, which will cause the activity to use a
61 * newly instantiated native view object.
62 */
63 @Override
65 return null;
66 }
67
68 @Override
69 public boolean retainFlutterNativeView() {
70 return false;
71 }
72
73 @Override
74 public final boolean hasPlugin(String key) {
75 return pluginRegistry.hasPlugin(key);
76 }
77
78 @Override
79 public final <T> T valuePublishedByPlugin(String pluginKey) {
80 return pluginRegistry.valuePublishedByPlugin(pluginKey);
81 }
82
83 @Override
84 public final Registrar registrarFor(String pluginKey) {
85 return pluginRegistry.registrarFor(pluginKey);
86 }
87
88 @Override
89 protected void onCreate(Bundle savedInstanceState) {
90 super.onCreate(savedInstanceState);
91 eventDelegate.onCreate(savedInstanceState);
92 }
93
94 @Override
95 protected void onStart() {
96 super.onStart();
97 eventDelegate.onStart();
98 }
99
100 @Override
101 protected void onResume() {
102 super.onResume();
103 eventDelegate.onResume();
104 }
105
106 @Override
107 protected void onDestroy() {
108 eventDelegate.onDestroy();
109 super.onDestroy();
110 }
111
112 @Override
113 public void onBackPressed() {
114 if (!eventDelegate.onBackPressed()) {
115 super.onBackPressed();
116 }
117 }
118
119 @Override
120 protected void onStop() {
121 eventDelegate.onStop();
122 super.onStop();
123 }
124
125 @Override
126 protected void onPause() {
127 super.onPause();
128 eventDelegate.onPause();
129 }
130
131 @Override
132 protected void onPostResume() {
133 super.onPostResume();
134 eventDelegate.onPostResume();
135 }
136
137 // @Override - added in API level 23
139 int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
140 eventDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
141 }
142
143 @Override
144 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
145 if (!eventDelegate.onActivityResult(requestCode, resultCode, data)) {
146 super.onActivityResult(requestCode, resultCode, data);
147 }
148 }
149
150 @Override
151 protected void onNewIntent(Intent intent) {
152 eventDelegate.onNewIntent(intent);
153 }
154
155 @Override
156 public void onUserLeaveHint() {
157 eventDelegate.onUserLeaveHint();
158 }
159
160 @Override
161 public void onWindowFocusChanged(boolean hasFocus) {
162 super.onWindowFocusChanged(hasFocus);
163 eventDelegate.onWindowFocusChanged(hasFocus);
164 }
165
166 @Override
167 public void onTrimMemory(int level) {
168 eventDelegate.onTrimMemory(level);
169 }
170
171 @Override
172 public void onLowMemory() {
173 eventDelegate.onLowMemory();
174 }
175
176 @Override
177 public void onConfigurationChanged(Configuration newConfig) {
178 super.onConfigurationChanged(newConfig);
179 eventDelegate.onConfigurationChanged(newConfig);
180 }
181}
void onActivityResult(int requestCode, int resultCode, Intent data)
final boolean hasPlugin(String key)
final Registrar registrarFor(String pluginKey)
void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
FlutterView createFlutterView(Context context)
FlutterNativeView createFlutterNativeView()
void onConfigurationChanged(Configuration newConfig)
void onCreate(Bundle savedInstanceState)
final< T > T valuePublishedByPlugin(String pluginKey)
void onWindowFocusChanged(boolean hasFocus)
void onWindowFocusChanged(boolean hasFocus)
void onCreate(Bundle savedInstanceState)
boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
boolean onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
boolean hasPlugin(@NonNull String pluginKey)
< T > T valuePublishedByPlugin(@NonNull String pluginKey)
Registrar registrarFor(@NonNull String pluginKey)
#define T
Definition: precompiler.cc:65
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63