سؤال

I'm working on an Android application. I have an activity that has this method:

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);
}

I'm parsing a text file on onCreate method this can be slow.

The ObjectParsed is defined on base class and it needs to be instated very super.onCreate(savedInstanceState); will be called.

And doing it right? Maybe Parse.parseFile(file) can be done in another method or by an asynchronous task.

Thanks.

هل كانت مفيدة؟

المحلول

Maybe Parse.parseFile(file) can be done in another method or by an asynchronous task.

You guessed it - if it takes non-negligible time you shouldn't be doing it on the UI thread.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top