0

我正在开发一个 Android 应用程序。我有一个具有这种方法的活动:

protected void onCreate(Bundle savedInstanceState)
{
    Bundle extraData = getIntent().getExtras();
    if (extraData == null) {
        throw new NullPointerException("We need a bundle object.");
    }
    else {
        String modelFileName = extraData.getString(Constants.MODEL_FILE_NAME);
        try {
            FileInputStream file = new FileInputStream(new File(modelFileName));
            ObjectParsed = Parse.parseFile(file);
        } catch (FileNotFoundException e) {
            return;
        }
    }
    // Call the base class version to initialize QCAR and setup
    // the required view:
    super.onCreate(savedInstanceState);
}

我正在解析一个文本文件,onCreate这可能很慢。

是在基类上定义的ObjectParsed,它需要super.onCreate(savedInstanceState);被调用。

并且做得对吗?也许Parse.parseFile(file)可以用另一种方法或异步任务来完成。

谢谢。

4

1 回答 1

2

也许 Parse.parseFile(file) 可以用另一种方法或异步任务来完成。

你猜对了——如果它花费了不可忽略的时间,你就不应该在 UI 线程上这样做。

于 2010-12-04T15:44:52.993 回答