在一些测试期间,我设法将模拟器冻结到我必须创建一个新模拟器的地步。在下面的代码中,我不小心拼错了一个类名Class.forName
threw
和RuntimeException()
ClassNotFoundException
. 然后ActivityManager
正在执行 Start proc org.acra.CrashReportDialog
。这是循环运行并冻结模拟器可能是因为onCreate()
永远无法完成,我不确定。
当 Emulator 启动时,我可以android.permission.RECEIVE_BOOT_COMPLETED
启动我的应用程序。
Class.forName
除了将代码移开Application
onCreate()
或编写更好的代码之外,还有什么方法可以防止这种情况发生吗?
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
ACRA.init(this);
ACRA.getErrorReporter().setReportSender(new AcraReportSender(this));
// gets id, create it if it dose not exist
ACRA.getErrorReporter().putCustomData("APPLICATION_ID_UUID", SettingsManager.applicationId());
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
ArrayList<String> contactManager = new ArrayList<String>();
TypedArray contactManagerClasses = getResources().obtainTypedArray(R.array.contact_managers);
for (int index = 0; index < contactManagerClasses.length(); index++)
contactManager.add(contactManagerClasses.getString(index));
contactManagerClasses.recycle();
TypedArray managerClasses = getResources().obtainTypedArray(R.array.managers);
for (int index = 0; index < managerClasses.length(); index++)
if (isContactsSupported() || !contactManager.contains(managerClasses.getString(index)))
try {
Class.forName(managerClasses.getString(index));
Log.d("Application","LOADING MANAGER " + managerClasses.getString(index));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
managerClasses.recycle();
TypedArray tableClasses = getResources().obtainTypedArray(R.array.tables);
for (int index = 0; index < tableClasses.length(); index++)
try {
Class.forName(tableClasses.getString(index));
Log.d("Application","LOADING TABLE " + managerClasses.getString(index));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
tableClasses.recycle();
onServiceStarted();
}
......
....