During some testing I managed to freeze the Emulator to the point that I have to create a new Emulator. In the below code I accidentally misspelled a class name and the Class.forName
threw
the RuntimeException()
ClassNotFoundException
. The ActivityManager
is then executing Start proc org.acra.CrashReportDialog
. This is running in a loop and freezes the Emulator probably because onCreate()
never gets to finish, I'm not sure.
When Emulator starts I have the android.permission.RECEIVE_BOOT_COMPLETED
that launches my app.
Is there any way to prevent this besides moving the Class.forName
code away from Application
onCreate()
or write better code?
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();
}
......
....
Short answer no.
Even if you removed ACRA you would find that your Activity is restarting over and over. That is because Android attempts to restart crashed apps. In your case it is crashing during construction of the app.
Best advice it to make your start up infallible.