1

I was trying to pass ability like we pass in android

Intent intent = new Intent(HomeActivity.this, cls);

But in Harmony we have to use operation builder so used this method

intent = new Intent();
Operation operation = new Intent.OperationBuilder().withBundleName(ability.getBundleName()).withAbilityName(name.toString()).build();
intent.setOperation(operation);

Here 'name' variable is class name.

I just wanted to know that is this the equivalent of the above android code. If not then what is the correct way

Raj Bhagat
  • 81
  • 5

1 Answers1

0

You can construct an Operation object with bundleName and abilityName specified to start and navigate to the particular ability. The sample code snippet is as follows:

Intent intent = new Intent();

// Use the OperationBuilder class of Intent to construct an Operation object and set the deviceId (left empty if a local ability is required), bundleName, and abilityName attributes for the object.
Operation operation = new Intent.OperationBuilder()
        .withDeviceId("")
        .withBundleName("com.demoapp")
        .withAbilityName("com.demoapp.FooAbility")
        .build();

// Set the created Operation object to the Intent as its operation attribute.
intent.setOperation(operation);
startAbility(intent);

For more details, pls refer to this Docs.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108