如何写精华回答,获更多曝光?
发布
代码写的没问题,调用FeatureAbility.continueAbility();返回的对象的code的值也是0,说明成功发起迁移了。但onStartContinuation等几个跟迁移有关的生命周期回调没有被调用,请问代码哪里出了问题,是照着官方给的案例写的。也对照的官方给的代码,没发现哪里写错了。工具里也调用了super device,也通过super app 启动程序了。
js代码如下:
import app from '@system.app';
export default {
data: {
appData:{
message:["demo1","demo2"],
msg:""
}
},
getMsg(e){
this.appData.msg = e.value;
},
send(){
console.info("---"+this.appData.message)
this.appData.message.push(this.appData.msg);
this.appData.msg = "";
console.info("---"+this.appData.message)
},
async start(){
let result = await FeatureAbility.continueAbility();
console.info("---result:" + JSON.stringify(result));
},
onStartContinuation(){
console.info("---onStartContinuation")
return true;
},
onSaveData(saveData){
Object.assign(saveData,this.appData);
//console.info("---onSaveData")
},
onRestoreData(restoreData){
this.appData = restoreData;
//console.info("---onRestoreData")
},
onCompleteContinuation(){
app.terminate();
//console.info("---onCompleteContinuation")
}
}
HML文件的代码如下:
<div class="container">
<div>
<list>
<list-item for="{{appData.message}}" class="msg-css">
<text >{{$item}}</text>
</list-item>
</list>
</div>
<div class="bottom-css">
<input type="text" @change="getMsg"></input>
<button type="capsule" @click="send">发送</button>
<button type="capsule" @click="switch">跳转</button>
<button type="capsule" @click="start">迁移</button>
</div>
</div>
权限也配置了
"ohos.permission.DISTRIBUTED_DATASYNC"权限也配置在config.json里了,
Java里也写了有关的代码
public class MainAbility extends AceAbility {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
requestPermissionsFromUser(new String[]{"ohos.permission.DISTRIBUTED_DATASYNC"},0);
}
@Override
public void onStop() {
super.onStop();
}