Question: After defining `FLAG_ACTIVITY_NO_ANIMATION` for the back arrow in the action bar to correct to animation when the toolbar back arrow is clicked, a warning is then returned. What is the best way to get rid of this warning?

> 
> Method invocation 'addFlags' may produce 'java.lang.NullPointerException'
> 
> 
> 

```
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        final Intent intent = getParentActivityIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        onBackPressed();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

```

Answer: 
Wrap it into an if intent != null.

```
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        final Intent intent = getParentActivityIntent();
        if(intent != null){
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        }else{
          //Do some error handling.
        }
        onBackPressed();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

```
From the doc of the `getParentActivityIntent`:

> 
> @return: a new Intent targeting the defined parent of this activity or null if
>  there is no valid parent.
> 
> 
> 

This method returns null only if there is no parent `Activity` and so they marked the `@Nullable` annotation for the return value. That's why you are getting the warning. 

If you are sure that you have defined the parent `Activity` in the manifest, you don't have to worry about the `NullPointerException`, you can suppress this warning. 

To suppress, you have to add `@SuppressWarnings("ConstantConditions")` to the method. 

And it is a good practice to add a comment above the annotation explaining why you have suppressed the warning.