UIAutomator -PressBack method is not working

I am in automating Android Native App using Appium Android driver , I need to work on Back , Search device buttons as part of transactions. I am giving below code , but not working. Can anyone provide me correct code for this.

UiDevice device = UiDevice.getInstance();
device.pressBack();
device.pressSearch();

/######### second one ####### , in this case it is throwing null pointer exception.
UiDevice device = null;
device.pressBack();

I have tried all the options available in previous posts answers but no use.

I did referrence of UIAutomator.jar and Android.jar to the project , still not working device operations.

Appreciate your help.

To navigate back, you can use:

driver.navigate().back()

I’m not sure what do you mean by search device button. Where that button placed in android device?