Page Ability 无法实现跳转
请大佬指点指点,刚刚接触 HarmonyOS
没有安卓的开发经历,所以很多问题都不太明白,请大佬们多多关照。
代码示例:
private void initComponent(){
tfUsername = (TextField) findComponentById(ResourceTable.Id_tf_username);
btnLogin = (Button) findComponentById(ResourceTable.Id_btn_login);
btnLogin.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder()
.withDeviceId("")
.withBundleName("com.arvin.PetiteBookkeeping")
.withAbilityName("MainAbility")
.build();
intent.setOperation(operation);
String username = tfUsername.getText().toString();
intent.setParam("username",username);
startAbility(intent);
}
});
btnRegister = (Button) findComponentById(ResourceTable.Id_btn_register);
btnRegister.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
Intent intent = new Intent();
present(new RegisterAbilitySlice(),intent);
}
});
}
报错码:
E/EGL_emulation: eglQuerySurface 313d EGL_BAD_ATTRIBUTE
···
D/AGP: can not find focus in [UILinearLayout ID(259) Id(-1)]
你的bundleName写对了么,还有withAbilityName(),是填你要跳转的Ability名称格式如下
com.example.myapplication.MainAbility
下方给出参考代码
Intent startService = new Intent();
Operation operation = new Intent.OperationBuilder()
.withDeviceId("")
.withBundleName(getBundleName())
.withAbilityName(MusicServiceAbility.class.getName())
.build();
startService.setOperation(operation);
startAbility(startService);
connectAbility(startService, connection);