【HarmonyOS】【DevEco Studio】NOTE05:PageAbility生命周期的呈现
NOTE05:PageAbility生命周期的呈现
基本界面设置
创建Slice与对应xml
BarAbilitySlice
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
public class BarAbilitySlice extends AbilitySlice {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_bar);
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
FooAbilitySlice
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
public class FooAbilitySlice extends AbilitySlice{
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_foo);
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
ability_bar.xml
<?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_bar"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="The Page Is Bar!"
ohos:text_size="40vp"
/>
</DirectionalLayout>
ability_foo.xml
<?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_foo"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="The Page Is Foo !"
ohos:text_size="40vp"
/>
</DirectionalLayout>
设置主页面
MainAbility
package com.example.myapplication;
import com.example.myapplication.slice.FooAbilitySlice;
import com.example.myapplication.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
public class MainAbility extends Ability {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setMainRoute(FooAbilitySlice.class.getName());
}
}
跳转设置
BarAbilitySlice
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
public class BarAbilitySlice extends AbilitySlice {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_bar);
Text text = findComponentById(ResourceTable.Id_text_bar);
text.setClickedListener(listener -> present(new FooAbilitySlice(),new Intent()));
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
FooAbilitySlice
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
public class FooAbilitySlice extends AbilitySlice{
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_foo);
Text text = findComponentById(ResourceTable.Id_text_foo);
text.setClickedListener(listener -> present(new BarAbilitySlice(),new Intent()));
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
重写生命周期方法
按下Crtl
+o
选择你需要重写的方法
打印HiLog日志
FooAbilitySlice
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
public class FooAbilitySlice extends AbilitySlice{
public static final HiLogLabel loglabel = new HiLogLabel(HiLog.LOG_APP,0x11102,"FooAbilitySlice");
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_foo);
Text text = findComponentById(ResourceTable.Id_text_foo);
text.setClickedListener(listener -> present(new BarAbilitySlice(),new Intent()));
}
@Override
public void onActive() {
HiLog.info(loglabel,"[xrilang]FooAbilitySlice onActive start");
super.onActive();
}
@Override
protected void onInactive() {
HiLog.info(loglabel,"[xrilang]FooAbilitySlice onInactive start");
super.onInactive();
}
@Override
protected void onBackground() {
HiLog.info(loglabel,"[xrilang]FooAbilitySlice onBackground start");
super.onBackground();
}
@Override
public void onForeground(Intent intent) {
HiLog.info(loglabel,"[xrilang]FooAbilitySlice onForeground start");
super.onForeground(intent);
}
@Override
protected void onStop() {
HiLog.info(loglabel,"[xrilang]FooAbilitySlice onstop start");
super.onStop();
}
}
BarAbilitySlice
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
public class BarAbilitySlice extends AbilitySlice {
public static final HiLogLabel loglabel = new HiLogLabel(HiLog.LOG_APP,0x11103,"BarAbilitySlice");
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_bar);
Text text = findComponentById(ResourceTable.Id_text_bar);
text.setClickedListener(listener -> present(new FooAbilitySlice(),new Intent()));
}
@Override
public void onActive() {
HiLog.info(loglabel,"[xrilang]BarAbilitySlice onActive start");
super.onActive();
}
@Override
protected void onInactive() {
HiLog.info(loglabel,"[xrilang]BarAbilitySlice onInactive start");
super.onInactive();
}
@Override
protected void onBackground() {
HiLog.info(loglabel,"[xrilang]BarAbilitySlice onBackground start");
super.onBackground();
}
@Override
protected void onStop() {
HiLog.info(loglabel,"[xrilang]BarAbilitySlice onStop start");
super.onStop();
}
@Override
public void onForeground(Intent intent) {
HiLog.info(loglabel,"[xrilang]BarAbilitySlice onForeground start");
super.onForeground(intent);
}
}
可以在搜索处搜索tag、key、以及一些你想要的字符
分析HiLog日志
【HarmonyOS】【DevEco Studio】NOTE05:PageAbility生命周期的呈现的更多相关文章
- Android Studio教程03-Activtiy生命周期的理解
目录 1. Activity 1.1. 安卓中的Activity定义和特性: 1.2. 注册Activity 1. Intent filters:设置默认开启的activity 1.3. Activi ...
- Android Studio 活动的生命周期
Activity 类中定义了7个回调方法,覆盖了活动的活动周期的每一环节 onCreate() 活动第一次创建的时候调用 onStart() 这个活动由不可见变为可见的时候调用 onResume() ...
- Android Studio 学习 - Activity生命周期
落下两晚了,继续学习…… 先粘贴2张官方给的流程图: ------------------------------------------------------------------------- ...
- Android Studio [Activity的生命周期]
package com.xdw.a122; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; imp ...
- ASP.NET编程模型之ASP.NET页面生命周期图解
ASP.NET编程模型中ASP.NET页面生命周期是指什么呢?它包括什么呢?ASP.NET编程模型之ASP.NET页面生命周期具体的过程有哪些呢?下面就开始我们的讲解吧: ASP.NET 页运行时,此 ...
- Android Studio 单刷《第一行代码》系列 06 —— Fragment 生命周期
前情提要(Previously) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Andr ...
- Android studio教程:[5]活动的生命周期
想要学好安卓开发,就必须理解安卓软件的生命周期,明白一个活动的创建.启动.停止.暂停.重启和销毁的过程,知道各个阶段会调用什么函数进行处理不同的情况,这里我就通过一个简单的例子让大家明白一个活动的生命 ...
- ASP.net 页面生命周期
ASP.NET 页面生命周期 Page_Preinit(); 在页初始化开始时发生 Page_Init(); 在所有控件初始化且应用外观设置后引发 Page_InitComplete(); 在页初始化 ...
- 详解ASP.NET MVC的请求生命周期
本文的目的旨在详细描述asp.net mvc请求从开始到结束的每一个过程. 我希望能理解在浏览器输入url并敲击回车来请求一个asp.net mvc网站的页面之后发生的任何事情. 为什么需要关心这些? ...
随机推荐
- 深入理解Spring IOC容器及扩展
本文将从纯xml模式.xml和注解结合.纯注解的方式讲解Spring IOC容器的配置和相关应用. 纯XML模式 实例化Bean的三种方式: 使用无参构造函数 默认情况下,会使用反射调用无参构造函数来 ...
- [noi37]列队
直接统计答案,令dp[i][j]表示前i个数最长的颜色各不相同后缀长度为j的方案数,如果一直令j<m,那么就相当于统计了方案数. 如何推出dp[i][j]呢?考虑i-1的最长前缀是多少:当小于j ...
- 日志审计功能-appent多个日志
public static void main(String[] args) { Jedis jedis = new Jedis("127.0.0.1"); jedis.setnx ...
- volatile不能保证数据完整性的小案例
package juc; import java.util.Collections; import java.util.HashSet; import java.util.Set; public cl ...
- 3个CSS动画库,比Animated还好用,让你的网站酷炫起来
本文首发于https://www.1024nav.com/tools/css-animation-library 转载请注明出处 整理了日常前端开发中常用的css动画库,让你的网页动起来,可以在生成中 ...
- Admixture的监督分群(Supervised analysis)
目录 说明 实战 说明 Admixture通过EM算法一般用于指定亚群分类:或者在不知材料群体结构背景下,通过迭代交叉验证获得error值,取最小error对应的K值为推荐亚群数目.如果我们预先已知群 ...
- Perl语言入门10-13
----------第十章 其他控制结构---------------- unless结构 unless($fred =~ /\A[A-Z_\w*\z]/i){print "yes" ...
- xshell的快捷复制粘贴设置
今天试着用xshell连接Linux,运行一些命令的时候想快点复制粘贴实现效率,却发现还要右键选择复制,再右键选择粘贴,很是麻烦. 看了一下xshell的设置,其实可以自己设置成快捷方式 以xshel ...
- EXCEL-名称管理器
1.怎么用? 两种方法 参考:https://jingyan.baidu.com/article/a378c960a26f26b3282830a6.html 2.有什么功能? (1)直接引用或者函数直 ...
- du命令之计算文件大小
在linux中,常用du命令来计算文件或目录的大小 名称: du - 计算每个文件的磁盘用量,目录则取总用量. 用法: du [选项]... [文件]... 常用选项 -a, --all 输出所有文件 ...