开发者

Can we perform some action whenever crash occurs in android

I want to perform implicit logout of my app when ever my app gets crash. So that when user does login again so that he will be having fresh data instead of incomplete开发者_StackOverflow社区 data that was caused by my crash.


You can register your Thread.UncaughtExceptionHandler on each thread that can crash. This will allow you to add some extra steps before crash is reported to Android. But be careful, because if your code throws another exception during those steps, you will never receive crash report to your Android Market account.

Basically, keep code inside your uncaught exception handler as simple as possible.

Here is an example:

public class MyUncaughtExceptionHandler implements UncaughtExceptionHandler {
    private final UncaughtExceptionHandler defaultHandler;

    MyUncaughtExceptionHandler(){
        defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
    }

    public void uncaughtException(Thread t, Throwable e) {
        //TODO: add your custom code here
        defaultHandler.uncaughtException(t,e);
    }  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜