IAssistanceChannel, IAbilityContinuation, ILifecycle, ContextAceDataAbility, AceServiceAbilitypublic class AceAbility extends Ability implements IAbilityContinuation, IAssistanceChannel
Ability. Any class specific to application running should derive from AceAbility.Ability.LayoutParamsHelper, Ability.WindowAttributeHelperFORM_INVISIBLE, FORM_VISIBLECONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESOUCE_ONLY, CONTEXT_RESTRICTED, MODE_APPEND, MODE_PRIVATE| 构造器 | 说明 |
|---|---|
AceAbility() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
protected void |
onAbilityResult(int requestCode,
int resultCode,
Intent resultData) |
Called when
Ability.startAbilityForResult(ohos.aafwk.content.Intent,int) is called to start an ability and the result is returned. |
void |
onActive() |
Called back when an ability enters the ACTIVE state.
|
void |
onBackground() |
Called back when an ability enters the BACKGROUND state.
|
void |
onBackPressed() |
Called back when the Back key is pressed.
|
void |
onCompleteContinuation(int code) |
Called back when a local ability migration is complete.
|
void |
onConfigurationUpdated(Configuration newConfig) |
Called when system configuration update.
|
void |
onConnected(AbilityAgent agent) |
Invoked by the framework to notify your application when a collaboration session is established using the
Ability#startAssistAbility method. |
void |
onConnectFailed(int errorCode) |
Invoked by the framework to notify your application when a collaboration session fails to be established using
the
Ability#startAssistAbility method. |
void |
onDisconnected(int errorCode) |
Invoked by the framework to notify your application when a collaboration session is disconnected.
|
void |
onForeground(Intent intent) |
Called back when the state of an ability changes from BACKGROUND to INACTIVE.
|
void |
onInactive() |
Called back when an ability enters the INACTIVE state (an ability in this state is not interactive and may
change to the BACKGROUND or ACTIVE state).
|
boolean |
onKeyDown(int keyCode,
KeyEvent keyEvent) |
Called when a key is pressed.
|
boolean |
onKeyUp(int keyCode,
KeyEvent keyEvent) |
Called when a key is released.
|
void |
onMemoryLevel(int level) |
Called when the system has determined to trim the memory, for example, when the ability is running in the
background and there is no enough memory for running as many background processes as possible.
|
void |
onNewIntent(Intent intent) |
Called when the launch mode of an ability is set to singleton.
|
void |
onNewWant(Intent intent) |
Called when the launch mode of an ability is set to singleton.
|
void |
onRemoteTerminated() |
Called to notify the local device when a running ability on the remote device is destroyed after a reversible
migration is performed for the ability from the local device to the remote device.
|
void |
onRequestPermissionsFromUserResult(int requestCode,
String[] permissions,
int[] grantResults) |
Called back after permissions are requested by using
AbilityContext.requestPermissionsFromUser(java.lang.String[],int). |
void |
onRestoreAbilityState(PacMap outState) |
Restores data and states of an ability when it is restored by the system.
|
boolean |
onRestoreData(IntentParams restoreData) |
Restores the user data saved during the migration for an ability on the remote device immediately after the
ability is created on the remote device.
|
void |
onSaveAbilityState(PacMap outState) |
Saves temporary data and states of this ability.
|
boolean |
onSaveData(IntentParams saveData) |
Saves the user data (carried in the
IntentParams object) of a local ability generated during runtime. |
void |
onStart(Intent intent) |
Called back when an ability is started for initialization (it can be called only once in the entire lifecycle of
an ability).
|
boolean |
onStartContinuation() |
Asks a user whether to start the migration.
|
void |
onStop() |
Called back before an ability is destroyed.
|
boolean |
onTouchEvent(TouchEvent event) |
Called when a touch event is dispatched to this ability.
|
void |
pushPage(String url,
IntentParams params) |
Navigates to another page in the application based on the page URL and parameters.
|
void |
setInstanceName(String name) |
Sets an instance name.
|
void |
setPageParams(String url,
IntentParams params) |
Sets page parameters.
|
addActionRoute, batchInsert, call, cancelBackgroundRunning, connectAbility, continueAbility, continueAbility, continueAbilityReversibly, continueAbilityReversibly, createPipeFile, delete, denormalizeUri, disconnectAbility, dispatchAccessibilityEventInfo, executeBatch, executeOperation, findComponentById, getAbilityName, getAbilityPackage, getAdmissionTransitionConcurEnabled, getAdmissionTransitionObject, getAVController, getBackTransitionConcurEnabled, getBackTransitionObject, getContinuationRegisterManager, getContinuationState, getCurrentFocus, getFileTypes, getIntent, getLayoutParams, getLifecycle, getOriginalDeviceId, getQuitTransitionObject, getReadmissionTransitionObject, getSharedItemAdmissionTransitionObject, getSharedItemBackTransitionObject, getSharedItemQuitTransitionObject, getSharedItemReadmissionTransitionObject, getState, getType, getVolumeTypeAdjustedByKey, getWindow, hasWindowFocus, insert, isTemporary, isTerminating, keepBackgroundRunning, normalizeUri, onAcquireFormState, onCastTempForm, onCommand, onCommand, onConnect, onCreateForm, onCreateForm, onDeleteForm, onDeleteForm, onDisconnect, onEventDispatch, onEventNotify, onHotkeyTriggered, onInitialized, onKeyPressAndHold, onLeaveForeground, onMissionDeleted, onNewDescription, onOrientationChanged, onPostActive, onPostStart, onReconnect, onSetCaller, onStoreDataWhenConfigChange, onTopActiveAbilityChanged, onTriggerFormEvent, onTriggerFormEvent, onUnloadForm, onUpdateForm, onUpdateForm, onWindowFocusChanged, openFile, openRawFile, parsePredictionArgsReference, parseValuesBucketReference, postTask, query, reload, reverseContinueAbility, setAbilitySliceAnimator, setAdmissionTransitionConcurEnabled, setAdmissionTransitionObject, setAVController, setBackTransitionConcurEnabled, setBackTransitionObject, setFormNextRefreshTime, setIntent, setIsAmbientMode, setLayoutParams, setMainRoute, setQuitTransitionObject, setReadmissionTransitionObject, setResult, setSharedItemAdmissionTransitionObject, setSharedItemBackTransitionObject, setSharedItemQuitTransitionObject, setSharedItemReadmissionTransitionObject, setSwipeToDismiss, setUIContent, setUIContent, setVolumeTypeAdjustedByKey, setWindowBackgroundColor, shutdown, startAbility, startAbility, startAbility, startAbility, startAbilityForResult, startAbilityForResult, startAssistAbility, stopAbility, stopAssistAbility, supportHighPerformanceUI, terminateAbility, update, updateForm, updateForm, updateForm, updateFormattachBaseContext, canRequestPermission, compelVerifyCallerPermission, compelVerifyCallerUriPermission, compelVerifyPermission, compelVerifyPermission, compelVerifyUriPermission, compelVerifyUriPermission, compelVerifyUriPermission, createBundleContext, createParallelTaskDispatcher, createSerialTaskDispatcher, deleteFile, displayUnlockMissionMessage, getAbilityInfo, getAbilityManager, getAbilityPackageContext, getApplicationContext, getApplicationInfo, getAppType, getBundleCodePath, getBundleManager, getBundleName, getBundleResourcePath, getCacheDir, getCaller, getCallingAbility, getCallingBundle, getClassloader, getCodeCacheDir, getColor, getColorMode, getContext, getDatabaseDir, getDataDir, getDir, getDisplayOrientation, getDistributedDir, getElementName, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getGlobalTaskDispatcher, getHapModuleInfo, getIntArray, getLastStoredDataWhenConfigChanged, getLocalClassName, getMainTaskDispatcher, getNoBackupFilesDir, getPattern, getPreferencesDir, getProcessInfo, getProcessName, getResourceManager, getResourceManager, getString, getString, getStringArray, getTheme, getThemeId, getUITaskDispatcher, init, isCredentialEncryptedStorage, isDeviceEncryptedStorage, isUpdatingConfigurations, lockMission, printDrawnCompleted, requestPermissionsFromUser, restart, setColorMode, setDisplayOrientation, setPattern, setShowOnLockScreen, setTheme, setTransitionAnimation, setWakeUpScreen, startAbilities, startAbility, startAbility, startAbility, switchToCredentialEncryptedStorageContext, switchToDeviceEncryptedStorageContext, terminateAbility, terminateAbilityResult, unlockMission, verifyCallingOrSelfPermission, verifyCallingPermission, verifyPermission, verifySelfPermissiononFailedContinuationpublic void onStart(Intent intent)
AbilityMost initialization operations should be performed by calling this method. For example, you can use the
current method to call Ability.setMainRoute(java.lang.String) and
Ability.addActionRoute(java.lang.String,java.lang.String) to set the main router and action router for a Page ability.
public void onConfigurationUpdated(Configuration newConfig)
onConfigurationUpdated 在类中 AbilitynewConfig - configuration information include locale.public void onSaveAbilityState(PacMap outState)
AbilityThis method is called when the system determines that the ability may be destroyed in an unexpected situation, for example, when the screen orientation changes or the user touches the Home key. Generally, this method is used only to save temporary states.
onSaveAbilityState 在类中 AbilityoutState - Indicates the PacMap object used for storing user data and states. This
parameter cannot be null.public void onRestoreAbilityState(PacMap outState)
AbilityThis method is called if an ability was destroyed at a certain time due to resource reclaim or was
unexpectedly destroyed and the Ability.onSaveAbilityState(ohos.utils.PacMap) method was called to save its user data and
states. Generally, this method is called after the Ability.onStart(ohos.aafwk.content.Intent) method.
onRestoreAbilityState 在类中 AbilityoutState - Indicates the PacMap object used for storing data and states. This
parameter can not be null.public void onMemoryLevel(int level)
onMemoryLevel 在类中 Abilitylevel - Indicates the memory trim level, which shows the current memory usage status.public void onStop()
AbilityThis method indicates the end of the ability lifecycle. It can be executed after the ability calls the
Ability.terminateAbility() method or the last ability slice of the ability calls the
AbilitySlice#terminate() method. Generally, this method is used to clear resources.
public void onNewIntent(Intent intent)
AbilityonNewIntent 在类中 Abilityintent - Indicates the new Intent containing information about the ability.public void onNewWant(Intent intent)
intent - Indicates the new Intent containing information about the ability.public void onBackPressed()
AbilityThe default implementation destroys the ability. You can override this method.
onBackPressed 在类中 Abilitypublic void onForeground(Intent intent)
AbilityThis is an intermediate state callback method. Generally, the system calls this method to refresh data status
and then calls back the Ability.onActive() method.
onForeground 在类中 Abilityintent - Indicates information carried when the ability returns to the INACTIVE state.public void onBackground()
AbilityA Page ability in the BACKGROUND state is invisible. You are advised to suspend threads related to the ability and clear some resources to free up system memory.
onBackground 在类中 Abilitypublic void onActive()
AbilityThe ability in the ACTIVE state is in the foreground and is interactive.
public void onInactive()
AbilityINACTIVE is an intermediate state and does not last for a long period of time. Frequent switching between ACTIVE and INACTIVE is possible. Therefore, you can use this method to perform certain simple operations, for example, committing any changes.
onInactive 在类中 Abilitypublic boolean onStartContinuation()
IAbilityContinuationThis method is called back when a local ability initiates a migration request.
If the Ability does not implement this method, this Ability cannot be migrated, and
false is returned. If the AbilitySlice does not implement this method, it does not affect
whether its host ability can be migrated, and true is returned by default.
onStartContinuation 在接口中 IAbilityContinuationtrue if the user allows the migration; returns false otherwise.public void onCompleteContinuation(int code)
IAbilityContinuationYou can define the processing logic after the migration is complete. For example, you can display a prompt to notify the user of the successful migration and then exit the local ability.
onCompleteContinuation 在接口中 IAbilityContinuationcode - Indicates the migration result code. The value 0 indicates that the migration is
successful, and -1 indicates that the migration fails.public boolean onSaveData(IntentParams saveData)
IAbilityContinuationIntentParams object) of a local ability generated during runtime.
After the migration is triggered and the local ability is ready, this method is called when the Distributed
Scheduler Service requests data from the local ability.onSaveData 在接口中 IAbilityContinuationsaveData - Indicates the user data to save.true if the data is successfully saved; returns false otherwise.public void onRemoteTerminated()
IAbilityContinuationAbility#continueAbilityReversibly() or
Ability#continueAbilityReversibly(String).onRemoteTerminated 在接口中 IAbilityContinuationpublic boolean onTouchEvent(TouchEvent event)
false.onTouchEvent 在类中 Abilityevent - Indicates information about the touch event.true if the event is handled; returns false otherwise.public boolean onKeyDown(int keyCode,
KeyEvent keyEvent)
Ability gains focus, the key-down event for
the component will be handled first. This callback will not be invoked if the callback triggered for the key-down
event of the component returns true. The default implementation of this callback does nothing and returns
false.onKeyDown 在类中 AbilitykeyCode - Indicates the code of the key pressed.keyEvent - Indicates the key-down event.true if this event is handled and will not be passed further;
returns false if this event is not handled and should be passed to other handlers.onKeyUp(int, ohos.multimodalinput.event.KeyEvent)public boolean onKeyUp(int keyCode,
KeyEvent keyEvent)
Ability gains focus, the key-up event for
the component will be handled first. This callback will not be invoked if the callback triggered for the key-up
event of the component returns true. The default implementation of this callback does nothing and returns
false.onKeyUp 在类中 AbilitykeyCode - Indicates the code of the key released.keyEvent - Indicates the key-up event.true if this event is handled and will not be passed further;
returns false if this event is not handled and should be passed to other handlers.onKeyDown(int, ohos.multimodalinput.event.KeyEvent)public boolean onRestoreData(IntentParams restoreData)
IAbilityContinuationonRestoreData 在接口中 IAbilityContinuationrestoreData - Indicates the user data to restore.true if the data is successfully restored; returns false otherwise.public void setInstanceName(String name)
The instance name must be the same as the module.js.name value in config.json.
MainAbility, call this method in the onStart method of the
Ability instance to set the instance name to MainAbility.default value
is retained, you do not need to call this method to set the instance name for the Ability instance.Note that this method must be called before the super.onStart method.
For an application with
multiple instances, the module.js field contains more than one name items. You need to
identify the item for the current instance.
Example code:
public class MainAbility extends AceAbility {
@Override
public void onStart(Intent intent) {
setInstanceName("MainAbility");
super.onStart(intent);
}
}
name - Indicates the instance name. The value cannot be an empty string. Otherwise, your application cannot
run properly.public void setPageParams(String url, IntentParams params)
You can use this method to set the home page URL and parameters. After the home page is successfully loaded,
you can use this.xxx (xxx: a parameter key) to obtain the parameter values. Note that this method must
be called before the super.onStart method.
Example code:
public class MainAbility extends AceAbility {
@Override
public void onStart(Intent intent) {
IntentParams intentParams = new IntentParams();
intentParams.setParam("key1", value1);
String url = "pages/index/index";
setPageParams(url, intentParams);
super.onStart(intent);
}
}
url - Indicates the page URL to set, which is an item in the pages clause of the config.json file.params - Indicates the page parameters to set.public void pushPage(String url, IntentParams params)
After the page is successfully loaded, you can use this.xxx (xxx: a parameter key) to obtain the
parameter values. Do not call this method in the onStart method.
Example code:
public class MainAbility extends AceAbility {
@Override
public void onNewIntent(Intent intent) {
IntentParams intentParams = new IntentParams();
intentParams.setParam("key1", value1);
String url = "pages/index/index";
pushPage(url, intentParams);
}
}
url - Indicates the page URL, which is an item in the pages clause of the config.json file.params - Indicates the page parameters.public void onRequestPermissionsFromUserResult(int requestCode,
String[] permissions,
int[] grantResults)
AbilityAbilityContext.requestPermissionsFromUser(java.lang.String[],int).onRequestPermissionsFromUserResult 在类中 AbilityrequestCode - Indicates the request code passed to this method from
AbilityContext.requestPermissionsFromUser(java.lang.String[],int).permissions - Indicates the list of permissions requested by using
AbilityContext.requestPermissionsFromUser(java.lang.String[],int). This parameter cannot be null.grantResults - Indicates the granting results of the corresponding permissions requested using
AbilityContext.requestPermissionsFromUser(java.lang.String[],int). The value 0 indicates
that a permission is granted, and the value -1 indicates not.protected void onAbilityResult(int requestCode,
int resultCode,
Intent resultData)
AbilityAbility.startAbilityForResult(ohos.aafwk.content.Intent,int) is called to start an ability and the result is returned.
This method is called only on Page abilities. You can start a new ability to perform some calculations and use
Ability.setResult(int,ohos.aafwk.content.Intent) to return the calculation result. Then the system calls back the current
method to use the returned data to execute its own logic.
onAbilityResult 在类中 AbilityrequestCode - Indicates the request code returned after the ability is started. You can define the request
code to identify the results returned by abilities. The value ranges from 0 to 65535.resultCode - Indicates the result code returned after the ability is started. You can define the result
code to identify an error.resultData - Indicates the data returned after the ability is started. You can define the data returned.
The value can be null.public void onConnected(AbilityAgent agent)
IAssistanceChannelAbility#startAssistAbility method.onConnected 在接口中 IAssistanceChannelagent - Indicates the agent of the peer ability.public void onConnectFailed(int errorCode)
IAssistanceChannelAbility#startAssistAbility method.onConnectFailed 在接口中 IAssistanceChannelerrorCode - Indicates the reason why the collaboration session fails to be established. For details about
the error code, see AssistantCode.public void onDisconnected(int errorCode)
IAssistanceChannelonDisconnected 在接口中 IAssistanceChannelerrorCode - Indicates the reason why the collaboration session is disconnected. For details about the
error code, see AssistantCode.