ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

Android Activity - APP 崩溃与自动重启观察记录、退出应用观察记录

2026/8/11 18:22:09 拓冰建站 浏览量
Android Activity - APP 崩溃与自动重启观察记录、退出应用观察记录

APP 崩溃与自动重启观察记录

1、观察记录 1
(1)准备阶段
  1. LoginActivity
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}
  1. ComputeActivity
valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{vala=10/0}
(2)测试
classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivity
2、观察记录 2
(1)准备阶段
  1. LoginActivity
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,MiddleActivity::class.java)intent.putExtra("data",100)startActivity(intent)}
  1. MiddleActivity
valtvMessage=findViewById<TextView>(R.id.tv_message)valbtnGo=findViewById<Button>(R.id.btn_go)valdata=intent.getIntExtra("data",0)if(data==0){throwIllegalArgumentException("data is 0")}tvMessage.text="data:$data"btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}
  1. ComputeActivity
valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{vala=10/0}
(2)测试
classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100
3、观察记录 3
(1)准备阶段
  1. LoginActivity
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}
  1. ComputeActivity
valtvResult=findViewById<TextView>(R.id.tv_result)valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{Thread{tvResult.text="1 + 2 = 3"}.start()}
(2)测试
classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}
奔溃,退回桌面 系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}
系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. throwable.printStackTrace() 打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}
奔溃,白屏 系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. throwable.printStackTrace() 打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}
奔溃,白屏 系统打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. throwable.printStackTrace() 打印:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. APP 自动重启,打开到 LoginActivity
4、观察记录 4
(1)准备阶段
  1. LoginActivity
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}
  1. ComputeActivity
valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{valname:String?=nullvallength=name!!.lengthprintln(length)}
(2)测试
classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}
奔溃,白屏 系统打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}
奔溃,白屏 系统打印:java.lang.NullPointerException throwable.printStackTrace() 打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}
奔溃,白屏 系统打印:java.lang.NullPointerException throwable.printStackTrace() 打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}
奔溃,白屏 系统打印:java.lang.NullPointerException throwable.printStackTrace() 打印:java.lang.NullPointerException APP 自动重启,打开到 LoginActivity
5、观察记录 5
(1)准备阶段
  1. LoginActivity
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}
  1. ComputeActivity
valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{Thread{vala=10/0}.start()}
(2)测试
classMyApplication:Application(){overridefunonCreate(){super.onCreate()}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()}}}
系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(0)}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivity
classMyApplication:Application(){overridefunonCreate(){super.onCreate()Thread.setDefaultUncaughtExceptionHandler{thread,throwable->throwable.printStackTrace()System.exit(1)}}}
奔溃,白屏 系统打印:java.lang.ArithmeticException: divide by zero throwable.printStackTrace() 打印:java.lang.ArithmeticException: divide by zero APP 自动重启,打开到 LoginActivity

退出应用观察记录

1、观察记录 1
(1)准备阶段
valbtnTest=findViewById<Button>(R.id.btn_test)btnTest.setOnClickListener{System.exit(0)}
(2)测试
System.exit(0)
退回桌面
System.exit(1)
退回桌面
2、观察记录 2
(1)准备阶段
  1. LoginActivity
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}
  1. ComputeActivity
valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{System.exit(0)}
(2)测试
System.exit(0)
退回桌面,白屏 APP 自动重启,打开到 LoginActivity
System.exit(1)
退回桌面,白屏 APP 自动重启,打开到 LoginActivity
3、准备阶段 3
(1)准备阶段
  1. LoginActivity
valbtnGo=findViewById<Button>(R.id.btn_go)btnGo.setOnClickListener{valintent=Intent(this,MiddleActivity::class.java)intent.putExtra("data",100)startActivity(intent)}
  1. MiddleActivity
valtvMessage=findViewById<TextView>(R.id.tv_message)valbtnGo=findViewById<Button>(R.id.btn_go)valdata=intent.getIntExtra("data",0)if(data==0){throwIllegalArgumentException("data is 0")}tvMessage.text="data:$data"btnGo.setOnClickListener{valintent=Intent(this,ComputeActivity::class.java)startActivity(intent)}
  1. ComputeActivity
valbtnCompute=findViewById<Button>(R.id.btn_compute)btnCompute.setOnClickListener{System.exit(0)}
(2)测试
System.exit(0)
退回桌面,白屏 APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100
System.exit(1)
退回桌面,白屏 APP 自动重启,打开到 MiddleActivity,MiddleActivity 显示:data: 100