目录

What should I do when error message 401"The context must be a valid Context" is reported during the use of UIAbilityContext?

Error code 401 indicates that the provided context type is incorrect. You need to use the context of the UIAbility. To obtain UIAbilityContext, use the code snippet below:

import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
    let uiAbilityContext = this.context;
    // ...
  }
}

Reference

Context (Stage Model)