天天看点

HarmonyOS开发58:Ability的生命周期

参考文档

HarmonyOS开发58:Ability的生命周期

分为四种状态

HarmonyOS开发58:Ability的生命周期

5、MainAbilitySlice.java

package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

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

        System.out.println("已经进入到闲置状态,准备进入到活跃状态");
    }

    @Override
    public void onActive() {
        super.onActive();
        System.out.println("已进入闲置状态,准备进入活跃状态");
    }

    @Override
    protected void onInactive() {
        super.onInactive();
        System.out.println("失去焦点了");
    }

    @Override
    protected void onBackground() {
        super.onBackground();
        System.out.println("完全被覆盖了");
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
        System.out.println("再次被调用了");
    }
}

           

来看一下Log

HarmonyOS开发58:Ability的生命周期