java Android应用程序在onCreate之前崩溃
我已经创建了一个在emulator(API 25、API 19)和设备(API 23)上运行良好的应用程序。然而,当我试图在带有API 19的KitKat设备上运行相同的应用程序时,应用程序崩溃
我创建了一个抽象的基本活动,所有其他活动都会扩展它
public abstract class BaseAppCompatActivity extends AppCompatActivity {
private Typeface OPEN_SANS_REGULAR = null;
private Typeface getOpenSans() {
if ( OPEN_SANS_REGULAR == null ) {
OPEN_SANS_REGULAR = Typeface.createFromAsset( this.getAssets(), FontConstants.OPEN_SANS_REGULAR );
}
return OPEN_SANS_REGULAR;
}
/**
* Set text to open Sans.
*
* @param view
*/
protected void useOpenSans( TextView view ) {
if ( OPEN_SANS_REGULAR == null ) {
OPEN_SANS_REGULAR = Typeface.createFromAsset( this.getAssets(), FontConstants.OPEN_SANS_REGULAR );
}
if ( null != OPEN_SANS_REGULAR ) {
view.setTypeface( OPEN_SANS_REGULAR );
}
}
protected void useOpenSans( TextView... views ) {
if ( OPEN_SANS_REGULAR == null ) {
OPEN_SANS_REGULAR = Typeface.createFromAsset( this.getAssets(), FontConstants.OPEN_SANS_REGULAR );
}
if ( null != OPEN_SANS_REGULAR ) {
for ( TextView view : views ) {
view.setTypeface( OPEN_SANS_REGULAR );
}
}
}
protected void useOpenSans( MenuItem item ) {
if( item != null ) {
SpannableString spannableString = new SpannableString(item.getTitle());
spannableString.setSpan(new OpenSansTypefaceSpan(getOpenSans()), 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
item.setTitle(spannableString);
}
}
protected void useOpenSans( SubMenu menus ) {
if( menus != null ) {
int size = menus.size(), i = 0;
for ( i = 0; i < size; i++ ) {
useOpenSans( menus.getItem( i ) );
}
}
}
protected void useOpenSans( Menu menus ) {
int size = menus.size(), i=0;
for( i=0; i<size; i++ ) {
MenuItem item = menus.getItem( i );
if( item != null ) {
useOpenSans( item );
useOpenSans( item.getSubMenu() );
}
}
}
@Override
public void finish() {
super.finish();
overridePendingTransitionExit();
}
@Override
public void startActivity( Intent intent ) {
super.startActivity( intent );
overridePendingTransitionEnter();
}
/**
* Overrides the pending Activity transition by performing the "Enter" animation.
*/
protected void overridePendingTransitionEnter() {
overridePendingTransition( R.anim.slide_from_right, R.anim.slide_to_left );
}
/**
* Overrides the pending Activity transition by performing the "Exit" animation.
*/
protected void overridePendingTransitionExit() {
overridePendingTransition( R.anim.slide_from_left, R.anim.slide_to_right );
}
public abstract String getTag();
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransitionExit();
}
/**
* Wrapped On Create.
* This is done to ensure that a mail is sent whenever an exception occurs.
*/
public abstract void wrappedOnCreate( Bundle savedInstanceState );
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
try{
wrappedOnCreate( savedInstanceState );
} catch ( Exception ex ){
Log.e( getTag(), "Caught Exception ex " + ex.getMessage(), ex );
Email email = new Email();
String subject = "Caught Exception ex " + ex.getClass().getName() + " with message " + ex.getMessage();
String body = ExceptionUtils.getStackTrace( ex );
email.setSubject( subject )
.setBody( body );
Mailer.send( email );
}
}
}
扩展此BaseAppCompactActivity
的所有活动都不会覆盖onCreate
,而是实现一个wrappedOnCreate
,该wrappedOnCreate
由一个try-catch块包围,该块在发生异常时发送邮件。梅勒说,它已经在模拟器和华硕设备上进行了测试
然而,在HTC设备(API 19)HTC Desire 816G上,应用程序在没有电子邮件触发的情况下崩溃。我不能把这个设备连接到Android监视器来查看LogCat
正如我所看到的,由于没有触发电子邮件,这意味着安卓在能够调用onCreate或wrappedOnCreate之前就遇到了错误
这可能是什么原因造成的
共 (0) 个答案