13.退出应用程序(递归和栈退出)

本文深入探讨了如何在使用递归时优雅地退出应用程序,详细解析了递归过程中栈的状态与退出机制。
摘要由CSDN通过智能技术生成

一.递归退出

递归执行方式:A调B,B跳C,C跳D。
当在D里面退出,就D跳C,C跳B,B跳A,然后就退出了(一个一个退)

效果图:


实现代码如下:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.zking.android13_activity.MainActivity"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="这是MainActivity"
        android:textSize="30sp"
        android:background="#00ff00"/><!--为了看效果的TextView-->

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv_main_text"
        android:textSize="25sp"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="(当前为A页面)跳自己"
        android:onClick="jumpMain"/><!--跳转(跳自己 即A跳A)-->

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="跳B页面"
        android:onClick="jumpB"/>

    <Button
        android:layout_width="match_parent"
        android:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值