This is my first android app so maybe this is a stupid question. So, please consider if I am doing any mistake.
I am building a app related to bluetooth.
I have a method in my MainActivity.java
:
public void showDeviceListDialog() {
BluetoothDeviceListDialog dialog = new BluetoothDeviceListDialog(this);
dialog.setOnDeviceSelectedListener(this);
dialog.setTitle("Paired Devices");
dialog.setDevices(bluetoothSerial.getPairedDevices());
dialog.showAddress(true);
dialog.show();
}
I need to call this method from another fragment. So, when I call this method like this: MainActivity.showDeviceListDialog();
it is asking for making the method Static. But when I am making it Static I am getting errors on "this" [ dialog.setOnDeviceSelectedListener(
this);
] on my method.
I have already read some posts like this and this but I didn't got help about my problem.
I have tried this from my fragment:
MainActivity mc = new MainActivity();
mc.showDeviceListDialog();
but this is showing NullPointerException.
So, Please tell me how to call it from my fragment without this errors. Thank you.