Phillip
Phillip

Reputation: 5676

Is there a way to tell whether an activity is starting?

Similar to Activity's isFinishing() API for use in onPause(), is there a good mechanism to determine whether the activity is being created when in onResume()?

Upvotes: 0

Views: 103

Answers (2)

IncrediApp
IncrediApp

Reputation: 10363

You can create a boolean value, initially false and you onResume should look something like this:

if (!flag)
{
    // Activity is created for the first time
    flag = true;
}
else
{
    // Activity was created before
}

Upvotes: 0

Luke Taylor
Luke Taylor

Reputation: 9599

You could have a boolean variable that saves the state of "isStarting".

boolean isStarting;

In your onCreate method, you'd set it to true:

isStarting = true;

So in you onResume() method you can check if the activity is starting:

    if(isStarting == true) {
    // Activity has been created!
//set the variable to false
isStarting = false;
    }
    else {
    // Nope...
    }

I hope this helps!

Upvotes: 1

Related Questions