├── SafeLooper.png ├── safelooper.apk ├── Sample ├── res │ ├── values │ │ └── strings.xml │ └── layout │ │ └── activity_main.xml ├── project.properties ├── AndroidManifest.xml ├── proguard-project.txt └── src │ └── com │ └── github │ └── mmin18 │ └── safelooper │ ├── MainActivity.java │ └── SafeLooper.java ├── .gitignore ├── README.md └── SafeLooper.java /SafeLooper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmin18/SafeLooper/HEAD/SafeLooper.png -------------------------------------------------------------------------------- /safelooper.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmin18/SafeLooper/HEAD/safelooper.apk -------------------------------------------------------------------------------- /Sample/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SafeLooper 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | -------------------------------------------------------------------------------- /Sample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-8 15 | -------------------------------------------------------------------------------- /Sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Sample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SafeLooper 2 | ========== 3 | 4 | SafeLooper catches unexpected exceptions in Android applications to avoid showing force close dialog. 5 | 6 | A normal Android application (except games) is driven by event loop, known as android.os.Looper. When you throw a uncaught exception in the main thread, the main thread's looper will stop and Android will show a force close dialog. You won't have a chance to recover the main thread's looper since it has already stopped. 7 | 8 | If you can create a sub looper, pull message from event queue and process it with a try-catch block, you can catch the unexpected exceptions and avoid the application from crash. 9 | 10 | Here is how a SafeLooper works: 11 | 12 | ![SafeLooper](https://raw.github.com/mmin18/SafeLooper/master/SafeLooper.png) 13 | 14 | All you need to do is import SafeLooper.java into your project and call SafeLooper.install() when your application start. 15 | 16 | 17 | // install SafeLooper in main thread 18 | SafeLooper.install(); 19 | 20 | // receive the uncaught exception if you don't want to ignore it 21 | SafeLooper.setUncaughtExceptionHandler(...); 22 | 23 | You can also test the on your device. 24 | -------------------------------------------------------------------------------- /Sample/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 15 | 16 |