简体   繁体   English

Android运行时错误:打开跟踪文件时出错:没有这样的文件或目录(2)

[英]Android runtime error: error opening trace file: No such file or directory (2)

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. 这是一个使用相机的Android应用程序,我希望该应用程序在显示Toast文本后退出,以便用户不会出现随机崩溃。 (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) (是的,理论上我不应该以if语句结尾,因为我的清单中需要摄像头硬件,但是我喜欢尽可能地处理错误)

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. 如您所见,我希望代码烘烤一下,然后关闭,但是它卡在了空白(黑屏)中(在System.exit(0)或之后),在Log中重复以下错误猫代替。

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? 我不能在OnCreate()函数中退出或举杯吗?

Do not use System.exit(0) 不要使用System.exit(0)

Quoting Romain Guy from https://groups.google.com/forum/#!topic/android-developers/G_D3pKnGLt0 https://groups.google.com/forum/#!topic/android-developers/G_D3pKnGLt0引用Romain Guy

The user doesn't, the system handles this automatically. 用户没有,系统会自动处理。 That's what the activity lifecycle (especially onPause/onStop/onDestroy) is for. 这就是活动生命周期(尤其是onPause / onStop / onDestroy)的用途。 No matter what you do, do not put a "quit" or "exit" application. 无论您做什么,都不要放置"quit""exit"应用程序。 It is useless with Android's application model. 它对Android的应用程序模型没有用。 This is also contrary to how core applications work. 这也与核心应用程序的工作方式相反。

There is detailed answer about the same @ 关于@的详细答案

Is quitting an application frowned upon? 退出应用程序会感到皱眉吗?

You can also read related threads @ 您也可以阅读相关主题@

https://groups.google.com/forum/#!topic/android-developers/G_D3pKnGLt0 https://groups.google.com/forum/#!topic/android-developers/G_D3pKnGLt0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android - 错误打开跟踪文件:没有这样的文件或目录 - Android - error opening trace file: No such file or directory Android E / Trace(627):打开跟踪文件时出错:没有这样的文件或目录(2) - Android E/Trace(627): error opening trace file: No such file or directory (2) Android上的JDom:打开跟踪文件时出错:没有这样的文件或目录 - JDom on Android: error opening trace file: No such file or directory 打开跟踪文件时出错:没有这样的文件或目录(2),解决方案? - error opening trace file: No such file or directory (2), Solution? HttpURLConnection打开跟踪文件时出错:没有这样的文件或目录 - HttpURLConnection Error opening trace file: no such file or directory 打开跟踪文件时出错。 没有这样的文件或目录[2] - Error opening trace file. No such file or directory [2] E / Trace:错误打开跟踪文件:没有这样的文件或目录(2) - E/Trace﹕ error opening trace file: No such file or directory (2) LogCat错误打开跟踪文件时出错:没有这样的文件或目录 - LogCat error Error opening trace file: no such file or directory 错误打开跟踪文件android权限被拒绝 - Error opening trace file android permission denied 是什么原因导致打开跟踪文件错误:没有这样的文件或目录? - What cause the error opening trace file: No such file or directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM