Android 系统API兼容性崩溃问题总结

由于使用系统Service的API,每个机型不同SDK版本对异常的处理结果各不相同,所以建议在使用系统API 多数应该优先考虑捕获系统异常,以减少崩溃。

 

(1) 隐士添加账号同步,相关代码如下:

public boolean addAccountExplicitly(Account account, String password, Bundle userdata) {
if (account == null) throw new IllegalArgumentException("account is null");
try {
return mService.addAccountExplicitly(account, password, userdata);
} catch (RemoteException e) {
// Can happen if there was a SecurityException was thrown.
throw new RuntimeException(e);
}
}

(2)JobSchedule builder问题 ,相关代码如下:

 

JobScheduler scheduler = (JobScheduler)context.getSystemService(JOB_SCHEDULER_SERVICE);
try {
scheduler.schedule(builder.build());
}catch (Exception e){
}

 


 

posted on 2017-09-07 10:18  大强5566  阅读(302)  评论(0编辑  收藏  举报

导航