Q:

Better way to handle null values in android?

Whenever I need to get some data from another activity/intent etc. in android my code essentially has to follow this logic:
Intent intent = getIntent();

if (intent != null) {
    String intentAction = intent.getAction();

    if (intentAction != null && intentAction.equals("whatever")) {

    // Do some stuff now that we know there are now  null values
    }
}

Very verbose and very nested code in my opinion and every time I do this I think to myself "there's gotta be a better way".  

Is there and what would that be?

A:

You can combine those if-statements into one. You won't get an error since the code will 'exit' once the first argument before the && returns false.
Intent intent = getIntent();

if (intent != null && intent.getAction() != null && intent.getAction().equals("whatever") {

    // Do some stuff now that we know there are now  null values

}

Or here's an even shorter way, thanks to a suggestion from @Tomkarho.
Intent intent = getIntent();

if (intent != null && "whatever".equals(intent.getAction()) {

    // Do some stuff now that we know there are now  null values

}

