1.同一activity间slice跳转
2.跳转不同activity
一 同一activity间slice跳转
日志类:声明+调用
public static final HiLogLabel hiLogLabel = new HiLogLabel(HiLog.LOG_APP, 0x00201, "ligy");
HiLog.info(hiLogLabel,"onClick 方法");
1.跳转到第二个slice
Button btn = (Button) findComponentById(ResourceTable.Id_btnNext); //跳转slice btn.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { present(new NextSlice(),new Intent()); HiLog.info(hiLogLabel,"onClick 方法"); } });
2.传值+回传
//跳转slice:传值+回传 btn.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { Intent param = new Intent(); param.setParam("id", "1"); param.setParam("name", "jack1"); presentForResult(new NextSlice(), param, 100); } });
@Override protected void onResult(int requestCode, Intent resultIntent) { super.onResult(requestCode, resultIntent); if (requestCode == 100) { if (resultIntent != null) { String msg = resultIntent.getStringParam("msg"); HiLog.info(hiLogLabel, "回传值:" + msg); } } }
public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_next); if(intent != null){ HiLog.info(hiLogLabel, intent.getStringParam("id")); HiLog.info(hiLogLabel, intent.getStringParam("name")); } Button btn = (Button)findComponentById(ResourceTable.Id_btnUp); btn.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { Intent t = new Intent(); t.setParam("msg","这是next返回的值"); //present(new MainAbilitySlice(),t); setResult(t); terminate(); } }); }
二 跳转不同activity
1.跳转到第二个activity
//跳转Ability btn.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { Intent intent1 = new Intent(); Operation operation = new Intent.OperationBuilder() .withDeviceId("") .withBundleName("com.example.myapplication3") .withAbilityName("com.example.myapplication3.TestAbility") .build(); intent1.setOperation(operation); startAbility(intent1); } });
2.传值+回传
同上