VansFannel
VansFannel

Reputation: 45921

Paring a file on onCreated method

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.

Upvotes: 0

Views: 135

Answers (1)

Chris Stratton
Chris Stratton

Reputation: 40347

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.

Upvotes: 2

Related Questions