关于ANR的问题 求教,如果程序发生anr,还会有log产生么。在activity启动过程中就发生anr,但是连oncreat里的log都没有请大牛指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 anr也有log的 首先adblog 会提示你 哪里产生了anr 在data/data/trace.*文件 里面就是anr log anr日志一般情况下好像是在data/anr/traces.txt至于没有执行onCreate方法,你自己也可以去截取adb log查看的 ANR只能说明主线程阻塞 如果子线程打印LOG无影响 我的程序是启动一个画图程序,因为是自定义了一个view继承了SurfaceView,然后creat中自定义view中的creat里的log也没有打印,activity中creat的log也没有打印,会发生这样的情况么。自定义view里会跑一个线程 这个activity是收到一个intent启动的,出现anr的情况时直接黑屏 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.paint); Calendar ca = Calendar.getInstance(); mGetTime = ca.getTimeInMillis(); paletteView = (PaletteView)findViewById(R.id.backview); bluepenButton = (Button)findViewById(R.id.bluepen); eraserButton = (Button)findViewById(R.id.eraserButton); submitButton = (Button)findViewById(R.id.submitButton); saveButton = (Button)findViewById(R.id.saveButton); bluepenButton.setOnClickListener(this); eraserButton.setOnClickListener(this); submitButton.setOnClickListener(this); saveButton.setOnClickListener(this); Bundle bundle = getIntent().getExtras(); token = bundle.getString("token"); readPath = bundle.getString("parameter"); subject = bundle.getString("subject"); mHttpPort = bundle.getInt("httpport"); Intent intent = new Intent(); intent.setAction("close.bynextQuiz"); sendBroadcast(intent); loadDialog = new ProgressDialog(this); saveDialog = new ProgressDialog(this); overtimeDialog = new AlertDialog.Builder(this).create(); overtimeDialog.setCancelable(false); loadDialog.setCancelable(false); saveDialog.setCancelable(false); msg = new Message(); resetActivity(); } public void resetActivity(){ if( subject == null || subject.equals("") ){ subject = "Miscellaneous"; } loadDialog.show(); loadDialog.setContentView(R.layout.loadpaintdialog); bluepenButton.setSelected(true); eraserButton.setSelected(false); thread = new Mythread(); thread.start(); }这是oncreat里的内容,在最开始添加log也没有任何输出。下面是oncreat里自定义view的内容: public PaletteView(Context context, AttributeSet arr) { super(context, arr); mPaint = new Paint(); actionList = new ArrayList<Action>(); mSurfaceHolder = this.getHolder(); mSurfaceHolder.addCallback(this); this.setFocusable(true); mLoop = true; finbgBitmap = ((BitmapDrawable) (getResources() .getDrawable(R.drawable.white))).getBitmap(); newbit = Bitmap.createBitmap(bgBitmapWidth, bgBitmapHeight, Config.ARGB_4444); myThread = new Thread(this); myThread.start(); } 自己顶一下,surfaceview的创建会造成anr么,finbgBitmap = ((BitmapDrawable) (getResources() .getDrawable(R.drawable.white))).getBitmap()或者创建Bitmap造成了anr 建议在可能耗时的方法前后加上时间点,找出耗时的方法,然后再进行优化处理。最好不要把耗时的方法放在onCreate里面 opengl移植问题 问一个简单的android布局问题 stagefright在哪个文件里面? 提供jar包还是给个service比较好呢 android获得Activity为Theme.Dialog Activity的值 导航布局,各个子activity如何设置标题栏?? 请问Contacts.People已过时,可以用谁来替代 gson 解析 为什么animation没有set方法设置属性? 怎么让Service不被kill掉或能自动重启 工程出错 如果Activity被回收,那么它打开的线程会不会自动关闭?
anr日志一般情况下好像是在data/anr/traces.txt至于没有执行onCreate方法,你自己也可以去截取adb log查看的
我的程序是启动一个画图程序,因为是自定义了一个view继承了SurfaceView,然后creat中自定义view中的creat里的log也没有打印,activity中creat的log也没有打印,会发生这样的情况么。自定义view里会跑一个线程
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.paint);
Calendar ca = Calendar.getInstance();
mGetTime = ca.getTimeInMillis();
paletteView = (PaletteView)findViewById(R.id.backview);
bluepenButton = (Button)findViewById(R.id.bluepen);
eraserButton = (Button)findViewById(R.id.eraserButton);
submitButton = (Button)findViewById(R.id.submitButton);
saveButton = (Button)findViewById(R.id.saveButton);
bluepenButton.setOnClickListener(this);
eraserButton.setOnClickListener(this);
submitButton.setOnClickListener(this);
saveButton.setOnClickListener(this);
Bundle bundle = getIntent().getExtras();
token = bundle.getString("token");
readPath = bundle.getString("parameter");
subject = bundle.getString("subject");
mHttpPort = bundle.getInt("httpport");
Intent intent = new Intent();
intent.setAction("close.bynextQuiz");
sendBroadcast(intent);
loadDialog = new ProgressDialog(this);
saveDialog = new ProgressDialog(this);
overtimeDialog = new AlertDialog.Builder(this).create();
overtimeDialog.setCancelable(false);
loadDialog.setCancelable(false);
saveDialog.setCancelable(false);
msg = new Message();
resetActivity();
}
public void resetActivity(){
if( subject == null || subject.equals("") ){
subject = "Miscellaneous";
}
loadDialog.show();
loadDialog.setContentView(R.layout.loadpaintdialog);
bluepenButton.setSelected(true);
eraserButton.setSelected(false);
thread = new Mythread();
thread.start();
}
这是oncreat里的内容,在最开始添加log也没有任何输出。下面是oncreat里自定义view的内容:
public PaletteView(Context context, AttributeSet arr) {
super(context, arr); mPaint = new Paint();
actionList = new ArrayList<Action>();
mSurfaceHolder = this.getHolder();
mSurfaceHolder.addCallback(this);
this.setFocusable(true);
mLoop = true; finbgBitmap = ((BitmapDrawable) (getResources()
.getDrawable(R.drawable.white))).getBitmap();
newbit = Bitmap.createBitmap(bgBitmapWidth, bgBitmapHeight,
Config.ARGB_4444);
myThread = new Thread(this);
myThread.start();
}
.getDrawable(R.drawable.white))).getBitmap()或者创建Bitmap造成了anr
最好不要把耗时的方法放在onCreate里面