public class FlutterActivity extends android.support.v4.app.FragmentActivity implements OnFirstFrameRenderedListener
Activity
which displays a fullscreen Flutter UI.
WARNING: THIS CLASS IS EXPERIMENTAL. DO NOT SHIP A DEPENDENCY ON THIS CODE. IF YOU USE IT, WE WILL BREAK YOU.
FlutterActivity
is the simplest and most direct way to integrate Flutter within an
Android app.
The Dart entrypoint executed within this Activity
is "main()" by default. The entrypoint
may be specified explicitly by passing the name of the entrypoint method as a String
in
EXTRA_DART_ENTRYPOINT
, e.g., "myEntrypoint".
The Flutter route that is initially loaded within this Activity
is "/". The initial
route may be specified explicitly by passing the name of the route as a String
in
EXTRA_INITIAL_ROUTE
, e.g., "my/deep/link".
The app bundle path, Dart entrypoint, and initial route can each be controlled in a subclass of
FlutterActivity
by overriding their respective methods:
Activity
, consider using
a FlutterFragment
. Using a FlutterFragment
requires forwarding some calls from
an Activity
to the FlutterFragment
.
If Flutter is needed in a location that can only use a View
, consider using a
FlutterView
. Using a FlutterView
requires forwarding some calls from an
Activity
, as well as forwarding lifecycle calls from an Activity
or a
Fragment
.
Modifier and Type | Class and Description |
---|---|
static class |
FlutterActivity.IntentBuilder
Builder to create an
Intent that launches a FlutterActivity with the
desired configuration. |
android.support.v4.app.SupportActivity.ExtraData
Modifier and Type | Field and Description |
---|---|
protected static String |
DART_ENTRYPOINT_META_DATA_KEY |
protected static String |
DEFAULT_DART_ENTRYPOINT |
protected static String |
DEFAULT_INITIAL_ROUTE |
protected static String |
EXTRA_DART_ENTRYPOINT |
protected static String |
EXTRA_INITIAL_ROUTE |
protected static String |
INITIAL_ROUTE_META_DATA_KEY |
DEFAULT_KEYS_DIALER, DEFAULT_KEYS_DISABLE, DEFAULT_KEYS_SEARCH_GLOBAL, DEFAULT_KEYS_SEARCH_LOCAL, DEFAULT_KEYS_SHORTCUT, FOCUSED_STATE_SET, RESULT_CANCELED, RESULT_FIRST_USER, RESULT_OK
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, COMPANION_DEVICE_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, CROSS_PROFILE_APPS_SERVICE, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, EUICC_SERVICE, FINGERPRINT_SERVICE, HARDWARE_PROPERTIES_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, IPSEC_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_STATS_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, PRINT_SERVICE, RECEIVER_VISIBLE_TO_INSTANT_APPS, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SHORTCUT_SERVICE, STORAGE_SERVICE, STORAGE_STATS_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_CLASSIFICATION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_AWARE_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_RANGING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
FlutterActivity() |
Modifier and Type | Method and Description |
---|---|
static FlutterActivity.IntentBuilder |
createBuilder()
Creates an
FlutterActivity.IntentBuilder , which can be used to configure an Intent to
launch a FlutterActivity . |
static Intent |
createDefaultIntent(Context launchContext)
Creates an
Intent that launches a FlutterActivity , which executes
a main() Dart entrypoint, and displays the "/" route as Flutter's initial route. |
protected FlutterFragment |
createFlutterFragment()
Creates the instance of the
FlutterFragment that this FlutterActivity displays. |
protected String |
getAppBundlePath()
The path to the bundle that contains this Flutter app's resources, e.g., Dart code snapshots.
|
protected String |
getDartEntrypoint()
The Dart entrypoint that will be executed as soon as the Dart snapshot is loaded.
|
protected FlutterEngine |
getFlutterEngine() |
protected String |
getInitialRoute()
The initial route that a Flutter app will render upon loading and executing its Dart code.
|
void |
onBackPressed() |
void |
onCreate(Bundle savedInstanceState) |
void |
onFirstFrameRendered()
A
FlutterRenderer has painted its first frame since being initialized. |
protected void |
onNewIntent(Intent intent) |
void |
onPostResume() |
void |
onRequestPermissionsResult(int requestCode,
String[] permissions,
int[] grantResults) |
void |
onTrimMemory(int level) |
void |
onUserLeaveHint() |
dump, getLastCustomNonConfigurationInstance, getLifecycle, getSupportFragmentManager, getSupportLoaderManager, getViewModelStore, onActivityResult, onAttachFragment, onConfigurationChanged, onCreatePanelMenu, onCreateView, onCreateView, onDestroy, onLowMemory, onMenuItemSelected, onMultiWindowModeChanged, onPanelClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsPanel, onPreparePanel, onResume, onResumeFragments, onRetainCustomNonConfigurationInstance, onRetainNonConfigurationInstance, onSaveInstanceState, onStart, onStateNotSaved, onStop, setEnterSharedElementCallback, setExitSharedElementCallback, startActivityForResult, startActivityForResult, startActivityFromFragment, startActivityFromFragment, startIntentSenderForResult, startIntentSenderForResult, startIntentSenderFromFragment, supportFinishAfterTransition, supportInvalidateOptionsMenu, supportPostponeEnterTransition, supportStartPostponedEnterTransition, validateRequestPermissionsRequestCode
dispatchKeyEvent, dispatchKeyShortcutEvent, getExtraData, putExtraData, superDispatchKeyEvent
addContentView, attachBaseContext, closeContextMenu, closeOptionsMenu, createPendingResult, dismissDialog, dismissKeyboardShortcutsHelper, dispatchGenericMotionEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, enterPictureInPictureMode, enterPictureInPictureMode, findViewById, finish, finishActivity, finishActivityFromChild, finishAffinity, finishAfterTransition, finishAndRemoveTask, finishFromChild, getActionBar, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getContentScene, getContentTransitionManager, getCurrentFocus, getFragmentManager, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLoaderManager, getLocalClassName, getMaxNumPictureInPictureActions, getMediaController, getMenuInflater, getParent, getParentActivityIntent, getPreferences, getReferrer, getRequestedOrientation, getSearchEvent, getSystemService, getTaskId, getTitle, getTitleColor, getVoiceInteractor, getVolumeControlStream, getWindow, getWindowManager, hasWindowFocus, invalidateOptionsMenu, isActivityTransitionRunning, isChangingConfigurations, isChild, isDestroyed, isFinishing, isImmersive, isInMultiWindowMode, isInPictureInPictureMode, isLocalVoiceInteractionSupported, isTaskRoot, isVoiceInteraction, isVoiceInteractionRoot, managedQuery, moveTaskToBack, navigateUpTo, navigateUpToFromChild, onActionModeFinished, onActionModeStarted, onActivityReenter, onApplyThemeResource, onAttachedToWindow, onAttachFragment, onChildTitleChanged, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreate, onCreateContextMenu, onCreateDescription, onCreateDialog, onCreateDialog, onCreateNavigateUpTaskStack, onCreateOptionsMenu, onCreatePanelView, onCreateThumbnail, onDetachedFromWindow, onEnterAnimationComplete, onGenericMotionEvent, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyShortcut, onKeyUp, onLocalVoiceInteractionStarted, onLocalVoiceInteractionStopped, onMenuOpened, onMultiWindowModeChanged, onNavigateUp, onNavigateUpFromChild, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPostCreate, onPostCreate, onPrepareDialog, onPrepareDialog, onPrepareNavigateUpTaskStack, onPrepareOptionsMenu, onProvideAssistContent, onProvideAssistData, onProvideKeyboardShortcuts, onProvideReferrer, onRestart, onRestoreInstanceState, onRestoreInstanceState, onSaveInstanceState, onSearchRequested, onSearchRequested, onTitleChanged, onTouchEvent, onTrackballEvent, onUserInteraction, onVisibleBehindCanceled, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, onWindowStartingActionMode, openContextMenu, openOptionsMenu, overridePendingTransition, postponeEnterTransition, recreate, registerForContextMenu, releaseInstance, removeDialog, reportFullyDrawn, requestDragAndDropPermissions, requestPermissions, requestShowKeyboardShortcuts, requestVisibleBehind, requestWindowFeature, requireViewById, runOnUiThread, setActionBar, setContentTransitionManager, setContentView, setContentView, setContentView, setDefaultKeyMode, setEnterSharedElementCallback, setExitSharedElementCallback, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setFinishOnTouchOutside, setImmersive, setIntent, setMediaController, setPictureInPictureParams, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setShowWhenLocked, setTaskDescription, setTheme, setTitle, setTitle, setTitleColor, setTurnScreenOn, setVisible, setVolumeControlStream, setVrModeEnabled, shouldShowRequestPermissionRationale, shouldUpRecreateTask, showAssist, showDialog, showDialog, showLockTaskEscapeMessage, startActionMode, startActionMode, startActivities, startActivities, startActivity, startActivity, startActivityFromChild, startActivityFromChild, startActivityFromFragment, startActivityFromFragment, startActivityIfNeeded, startActivityIfNeeded, startIntentSender, startIntentSender, startIntentSenderFromChild, startIntentSenderFromChild, startLocalVoiceInteraction, startLockTask, startManagingCursor, startNextMatchingActivity, startNextMatchingActivity, startPostponedEnterTransition, startSearch, stopLocalVoiceInteraction, stopLockTask, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterForContextMenu
applyOverrideConfiguration, getAssets, getResources, getTheme
bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getSharedPreferences, getSystemServiceName, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, setWallpaper, startForegroundService, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onPointerCaptureChanged
protected static final String DART_ENTRYPOINT_META_DATA_KEY
protected static final String INITIAL_ROUTE_META_DATA_KEY
protected static final String EXTRA_DART_ENTRYPOINT
protected static final String EXTRA_INITIAL_ROUTE
protected static final String DEFAULT_DART_ENTRYPOINT
protected static final String DEFAULT_INITIAL_ROUTE
public static Intent createDefaultIntent(@NonNull Context launchContext)
Intent
that launches a FlutterActivity
, which executes
a main()
Dart entrypoint, and displays the "/" route as Flutter's initial route.public static FlutterActivity.IntentBuilder createBuilder()
FlutterActivity.IntentBuilder
, which can be used to configure an Intent
to
launch a FlutterActivity
.public void onCreate(Bundle savedInstanceState)
onCreate
in class android.support.v4.app.FragmentActivity
@NonNull protected FlutterFragment createFlutterFragment()
FlutterFragment
that this FlutterActivity
displays.
Subclasses may override this method to return a specialization of FlutterFragment
.
public void onPostResume()
onPostResume
in class android.support.v4.app.FragmentActivity
protected void onNewIntent(Intent intent)
onNewIntent
in class android.support.v4.app.FragmentActivity
public void onBackPressed()
onBackPressed
in class android.support.v4.app.FragmentActivity
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
onRequestPermissionsResult
in interface android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback
onRequestPermissionsResult
in class android.support.v4.app.FragmentActivity
public void onUserLeaveHint()
onUserLeaveHint
in class Activity
public void onTrimMemory(int level)
onTrimMemory
in interface ComponentCallbacks2
onTrimMemory
in class Activity
@Nullable protected FlutterEngine getFlutterEngine()
@NonNull protected String getAppBundlePath()
When this FlutterActivity
is run by Flutter tooling and a data String is included
in the launching Intent
, that data String is interpreted as an app bundle path.
By default, the app bundle path is obtained from FlutterMain.findAppBundlePath(Context)
.
Subclasses may override this method to return a custom app bundle path.
@NonNull protected String getDartEntrypoint()
This preference can be controlled with 2 methods:
String
as EXTRA_DART_ENTRYPOINT
with the launching Intent
, or<meta-data>
called DART_ENTRYPOINT_META_DATA_KEY
for this
Activity
in the Android manifest.Intent
preference takes priority.
The reason that a <meta-data>
preference is supported is because this Activity
might be the very first Activity
launched, which means the developer won't have
control over the incoming Intent
.
Subclasses may override this method to directly control the Dart entrypoint.
@NonNull protected String getInitialRoute()
This preference can be controlled with 2 methods:
EXTRA_INITIAL_ROUTE
with the launching Intent
, or<meta-data>
called INITIAL_ROUTE_META_DATA_KEY
for this
Activity
in the Android manifest.Intent
preference takes priority.
The reason that a <meta-data>
preference is supported is because this Activity
might be the very first Activity
launched, which means the developer won't have
control over the incoming Intent
.
Subclasses may override this method to directly control the initial route.
public void onFirstFrameRendered()
OnFirstFrameRenderedListener
FlutterRenderer
has painted its first frame since being initialized.
This method will not be invoked if this listener is added after the first frame is rendered.onFirstFrameRendered
in interface OnFirstFrameRenderedListener