I did some search and found people who ended up with the same error as I did, but in a completely different context :(
So, I'm trying to get my app to gracefully exit when something critical happens. It's an android app that uses camera, and I want the app to quit after showing a toast text, so the users don't get a random crash. (And yes, theoretically I shouldn't end up in the if statement because I require a camera hardware in my manifest, but I like handling error as much as possible)
Here's a snippet of the manifest file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
And here's my code:
public class MainActivity extends Activity {
/* member variables... */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create an instance of Camera
// I forced this to true for testing because the devices I'm testing
// against won't reach inside the if statement
if (/*!(checkCameraHardware(this) || checkFrontFacingCameraHardware(this))*/ true) {
Toast.makeText(getBaseContext(), "Shutting Down! No Camera Detected!", Toast.LENGTH_SHORT).show();
System.exit(0); // This is the last code it reaches
}
mCamera = getCameraInstance(); // This code isn't reached
As you can see, I would like the code to make a toast, then shut down, but it gets stuck in a blank (black) screen instead (at or right after System.exit(0)
), repeating the following error in Log Cat instead.
Tag: Trace, Text: error opening trace file: No such file or directory (2)
Did I miss something? Can I not exit or toast in the OnCreate() function?