当前位置:   article > 正文

记录一下HarmonyOS开发app时跳转Ability(withAction方法)无反应的问题_harmony开发页面跳转卡住

harmony开发页面跳转卡住

解决方案

    换设备,找一台能跳转的设备。具体原因还不知道。
    代码写的不一定规范,且不说更新的问题,这个只是在测试跳转。

环境

    DevEco Studio 3.0.0.993 Release
    SDK 6(使用java)

问题展示

图1

代码展示

Ability

MainAbility

package com.openvally.cyj;

import com.openvally.cyj.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName());
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

PayAbility

package com.openvally.cyj;

import com.openvally.cyj.slice.Pay2AbilitySlice;
import com.openvally.cyj.slice.PayAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class PayAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(PayAbilitySlice.class.getName());

        addActionRoute();
    }

    //添加路由
    private void addActionRoute(){
        addActionRoute("action.pay2", Pay2AbilitySlice.class.getName());
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

AbilitySlice

MainAbilitySlice

package com.openvally.cyj.slice;

import com.openvally.cyj.PayAbility;
import com.openvally.cyj.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.utils.IntentConstants;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        toPayAbility();
        toPay2Ability();
        toDialPage();
    }

    //跳转到payAbility
    private void toPayAbility(){
        Text text_to_payAbility = (Text)findComponentById(ResourceTable.Id_text_to_payAbility);
        text_to_payAbility.setClickedListener(listen -> {
            new ToastDialog(getContext())
                    .setText("test1")
                    .setAlignment(LayoutAlignment.CENTER)
                    .show();
            Intent intentSend = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(PayAbility.class.getName())
                    .build();
            intentSend.setOperation(operation);
            startAbility(intentSend);
        });
    }

    //跳转到pay2Ability
    private void toPay2Ability() {
        Text text_to_pay2Ability = (Text) findComponentById(ResourceTable.Id_text_to_pay2Ability);
        text_to_pay2Ability.setClickedListener(listen ->{
                new ToastDialog(getContext())
                        .setText("test2")
                        .setAlignment(LayoutAlignment.CENTER)
                        .show();
                Intent intentSend = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withAction("action.pay2")
                        .build();
                intentSend.setOperation(operation);
                startAbility(intentSend);
            });
        }

    //跳转到拨号页面
    private void toDialPage() {
        Text text_to_pay2Ability = (Text) findComponentById(ResourceTable.Id_text_to_dialPage);
        text_to_pay2Ability.setClickedListener(listen ->{
            new ToastDialog(getContext())
                    .setText("test3")
                    .setAlignment(LayoutAlignment.CENTER)
                    .show();
            Intent intentSend = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withAction(IntentConstants.ACTION_DIAL)
                    .build();
            intentSend.setOperation(operation);
            startAbility(intentSend);
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

PayAbilitySlice

package com.openvally.cyj.slice;

import com.openvally.cyj.PayAbility;
import com.openvally.cyj.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class PayAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_pay);
    }
    @Override
    public void onActive() {
        super.onActive();
    }
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

Pay2AbilitySlice

package com.openvally.cyj.slice;

import com.openvally.cyj.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

public class Pay2AbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_pay2);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

Resources/layout

ability_main

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">
    <Text
        ohos:id="$+id:text_to_payAbility"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:layout_alignment="horizontal_center"
        ohos:text="精确跳转到PayAbility"
        ohos:text_size="30vp"
        />
    <Text
        ohos:id="$+id:text_to_pay2Ability"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:layout_alignment="horizontal_center"
        ohos:text="模糊跳转到Pay2Ability"
        ohos:text_size="30vp"
        />
    <Text
        ohos:id="$+id:text_to_dialPage"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:layout_alignment="horizontal_center"
        ohos:text="跳转到DialPage"
        ohos:text_size="30vp"
        />
</DirectionalLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

ability_pay

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">
    <Text
        ohos:id="$+id:text_payAbility"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:layout_alignment="horizontal_center"
        ohos:text="This is PayAbility"
        ohos:text_size="30vp"
        />
</DirectionalLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

ability_pay2

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">
    <Text
        ohos:id="$+id:text_payAbility"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:layout_alignment="horizontal_center"
        ohos:text="This is Pay2Ability"
        ohos:text_size="30vp"
        />
</DirectionalLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

config.json

{
  "app": {
    "bundleName": "com.openvally.cyj",
    "vendor": "example",
    "version": {
      "code": 1000000,
      "name": "1.0.0"
    }
  },
  "deviceConfig": {
  },
  "module": {
    "package": "com.openvally.cyj",
    "name": ".MyApplication",
    "mainAbility": "com.openvally.cyj.MainAbility",
    "deviceType": [
      "phone",
      "tablet"
    ],
    "distro": {
      "deliveryWithInstall": true,
      "moduleName": "entry",
      "moduleType": "entry",
      "installationFree": false
    },
    "abilities": [
      {
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              "action.system.home"
            ]
          }
        ],
        "name": "com.openvally.cyj.MainAbility",
        "description": "$string:mainability_description",
        "icon": "$media:icon",
        "label": "$string:entry_MainAbility",
        "launchType": "standard",
        "orientation": "unspecified",
        "visible": true,
        "type": "page"
      },
      {
        "skills": [
          {
            "actions": [
              "action.pay2"
            ]
          }
        ],
        "name": "com.openvally.cyj.PayAbility",
        "description": "$string:payability_description",
        "icon": "$media:icon",
        "label": "$string:entry_PayAbility",
        "launchType": "standard",
        "orientation": "unspecified",
        "visible": true,
        "type": "page"
      }
    ]
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66

目录结构

图2

解决后展示

图3

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/247494
推荐阅读
相关标签
  

闽ICP备14008679号