1

I am trying to move from an AbilitySlice to an Ability. I tried the below code, But was it not working as expected.

Operation systemOperation = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(MainAbility.class.getSimpleName())
                        .build();
                intent.setOperation(systemOperation);
                startAbility(intent);

for moving from an AbilitySlice to Ability in Harmony OS?

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
Sahana G R
  • 31
  • 1
  • Have you mentioned your Target Ability in Config.json @Sahana G R, reference usage : https://gitee.com/openharmony-tpc/BottomBar/blob/master/entry/src/main/java/com/example/bottombar/sample/slice/MainAbilitySlice.java – Gowtham GS Aug 09 '21 at 04:59

3 Answers3

0

Try to Delete Simple from getSimpleName. Like following:

Operation systemOperation = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(MainAbility.class.getName())
                        .build();
                intent.setOperation(systemOperation);
                startAbility(intent);
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • Error message: 08-09 20:24:57.310 7136-7136/com.github.mzelzoghbi E 01100/AppExecFwk: ContextDeal::getAbilityShellDatasLocal failed, abilityInfos is empty 08-09 20:24:57.310 7136-7136/com.github.mzelzoghbi I 02D03/HiTraceC: [807f221e994be28, 0, 0] HiTraceBegin name:fetchAbilities flags:1. 08-09 20:24:57.319 7136-10149/com.github.mzelzoghbi E 01100/AbilityShell: DistributedManager::fetchAbilities sendRequest failed 08-09 20:24:57.319 7136-7136/com.github.mzelzoghbi E 01100/AppExecFwk: [807f221e994be28, 0, 0] ContextDeal::startAbility fetchAbilities failed – Sahana G R Aug 09 '21 at 12:31
  • i tried the code mentioned above. not working – Sahana G R Aug 09 '21 at 12:32
  • For details, you may refer the following development document : [link1](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ability-ability-overview-0000000000029852) [link2](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ability-intent-0000000000038799) [link 3](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ability-page-switching-0000000000037999), this might help you solve the problem. – zhangxaochen Aug 17 '21 at 07:09
0

"Not working as expected" generally is not a valid error description. I'd suspect the AbilitySlice might belong to MainAbility and the whole operation might therefore be pointless, as navigation from A to B could not happen. The example which @Gowtham provided has one small difference (which appears to consider the device on which to launch the Intent with Super Device):

 .withDeviceId("")

Have you ever tried to start anything else but MainAbility?

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

I see that you have mentioned that the package name of your target ability is different than the package name of your ability slice in your reply to @Martin. Then, you need to make sure the bundleName(or package name) specified in the Intent's Operation builder is having the target ability's package name and not the calling ability's/abilityslice's package name.

Operation systemOperation = new Intent.OperationBuilder()
                        .withBundleName("enter_package_name_of target_ability_here")
                        .withAbilityName(MainAbility.class.getName())
                        .build();
                intent.setOperation(systemOperation);
                startAbility(intent);
Samuel
  • 36
  • 3