I found that FragmentStatePagerAdapter(or something else, maybe ViewPager, I don't know) catches exceptions silently and causes ANR.
For Example:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public static class MyPagerAdapter extends FragmentStatePagerAdapter {
private List<String> data;
public TabPagerAdapter(FragmentManager fm, List<String> data) {
super(fm);
int a = 1 / 0; // ANR instead of crash
this.data = data;
}
@Override
public Fragment getItem(int pos) {
int a = 1 / 0; // ANR instead of crash
return MyFragment.newInstance(data.get(pos));
}
@Override
public int getCount() {
int a = 1 / 0; // ANR instead of crash
return data.size();
}
@Override
public CharSequence getPageTitle(int position) {
int a = 1 / 0; // ANR instead of crash
return data.get(position);
}
}
All I can found in the logcat is:
D/AndroidRuntime(14277): Shutting down VM
W/dalvikvm(14277): threadid=1: thread exiting with uncaught exception (group=0x41a2d9a8)
What should I do to enable the logcat(for debug)? My current workaround is adding try-catch for every method in FragmentStatePagerAdapter.