MyApplication.java
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.hjx.personalcenter.activity;
import android.app.Application;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Looper;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;
import com.hjx.personalcenter.R;
import com.hjx.personalcenter.crash.CrashHandler;
import com.hjx.personalcenter.util.ImageCache;
import com.tencent.bugly.crashreport.CrashReport;
/**
* Created by ${yf} on 2017/2/16.
*/
public class MyApplication extends Application {
private ImageCache mImageCache;
private static Context context;
private static MyApplication instance;
@Override
public void onCreate() {
context = getApplicationContext();
//c初始化内存检测
// LeakCanary.install(this);
//初始化Fresco
mImageCache = new ImageCache();
instance = this;
CrashReport.initCrashReport(getApplicationContext(), "c2170557a0", false);
CrashHandler crashHandler = CrashHandler.getInstance();
//生成错误日志,上线的时候得放开
//crashHandler.init(getApplicationContext());
crashHandler.registerHandler(new CrashHandler.ExceptionHandler() {
@Override
public boolean handleCrash(final Context context, final Throwable ex) {
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
System.out.println("bcz = " + ex.toString());
Toast toast = new Toast(context);
TextView tv = new TextView(context);
tv.setText(" 很抱歉,"+context.getString(R.string.app_name)+"崩溃了,我们会尽快修复.");
tv.setPadding(10, 10, 10, 10);
tv.setTextSize(20);
tv.setBackgroundResource(R.drawable.black_btn_default);
tv.setTextColor(context.getResources().getColor(android.R.color.white));
Drawable drawable= context.getResources().getDrawable(R.drawable.sorry);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
tv.setCompoundDrawables(drawable,null,null,null);
toast.setView(tv);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
Looper.loop();
}
}).start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
});
super.onCreate();
}
public ImageCache getImageCache() {
return mImageCache;
}
public static Context getContext() {
return context;
}
public static MyApplication getInstance() {
return instance;
}
}