惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
W
WeLiveSecurity
IT之家
IT之家
A
About on SuperTechFans
B
Blog
L
LangChain Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
Google Online Security Blog
Google Online Security Blog
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
Schneier on Security
Schneier on Security
GbyAI
GbyAI
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Cloudbric
Cloudbric
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
S
Security Affairs
The Last Watchdog
The Last Watchdog
H
Heimdal Security Blog
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Privacy & Cybersecurity Law Blog
V
Visual Studio Blog
H
Hacker News: Front Page
Recorded Future
Recorded Future
Cyberwarzone
Cyberwarzone
L
Lohrmann on Cybersecurity
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
Jina AI
Jina AI
N
News | PayPal Newsroom
S
Schneier on Security

博客园 - gAmesaceR

cocos 3.16 生成预编译库模板 安装Jenkins Sublime发布Markdown博客 Markdown Example 关于测试驱动的学习 关于领域驱动的学习 (zt)Lua的多任务机制——协程(coroutine) (zt)IOS开发常用的开源类库和一些示例 (zt)过程生成 Node.js源码研究之模块组织加载 [zt][cocos2d-x-win32] 安装部署流程整理 (转发)iOS使用WebGL (转发)XCode实现WebSocket (ZT)UIImage应用与内存管理 (ZT)为什么iPad版FaceBook值得我们苦苦等待 (ZT)关于IAP防止破解的几点 (ZT)iPhone为什么比Android好 在Mac上发布QT的程序 斯坦福大学公开课 iPhone开发教程
app崩溃后自动重启
gAmesaceR · 2017-10-10 · via 博客园 - gAmesaceR

android

引用:http://blog.csdn.net/caiwenfeng_for_23/article/details/41184353

package com.tan.abnormalrestart; import java.lang.Thread.UncaughtExceptionHandler; import android.app.Application; import android.content.Intent; public class AppContext extends Application { protected static AppContext instance; public void onCreate() { super.onCreate(); instance = this; Thread.setDefaultUncaughtExceptionHandler(restartHandler); // 程序崩溃时触发线程 以下用来捕获程序崩溃异常 } // 创建服务用于捕获崩溃异常 private UncaughtExceptionHandler restartHandler = new UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable ex) { restartApp();//发生崩溃异常时,重启应用 } }; public void restartApp(){ Intent intent = new Intent(instance,MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); instance.startActivity(intent); android.os.Process.killProcess(android.os.Process.myPid()); //结束进程之前可以把你程序的注销或者退出代码放在这段代码之前 } }

iOS

引用:http://blog.sina.com.cn/s/blog_b71d24920101ky2d.html

  1. 在程序启动时加上一个异常捕获监听,用来处理程序崩溃时的回调动作
    NSSetUncaughtExceptionHandler (&UncaughtExceptionHandler);
    官方文档介绍:Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.
    UncaughtExceptionHandler是一个函数指针,该函数需要我们实现,可以取自己想要的名字。当程序发生异常崩溃时,该函数会得到调用,这跟C,C++中的回调函数的概念是一样的。

  2. 实现自己的处理函数

void UncaughtExceptionHandler(NSException *exception) { NSArray *arr = [exception callStackSymbols];//得到当前调用栈信息 NSString *reason = [exception reason];//非常重要,就是崩溃的原因 NSString *name = [exception name];//异常类型 NSLog(@"exception type : %@ \n crash reason : %@ \n call stack info : %@", name, reason, arr); }

以上代码很简单,但是带来的作用是非常大的。