i am making a bluetooth service in android studio. i execute the service in a single activity successfully using some post in stackOverFlow like : How to move Bluetooth activity into a Service but when i want to send data from a second activity that extends first activity, to the bluetooth device i got a "null object reference".
public void onClick(View v) {
sendToDevice(editSendData.getText().toString());
}
sendToDevice is a non-private method in MainActivity(first Activity):
public void sendToDevice(String inMain){
printerService.sendingData(inMain);
Log.i("3","thread id:\n"+"send1");
}
//printerService is bluetoothService
//sendData is a method in bluetoothService that uses bytes of "inMain" to send data using outputStream
i do not know why but as i know, when second activity extends first activity(an activity is class), it also extends non-private methods of first activity. so why this error occurs?
i did not find a question like this one but there was a question in the comment of another question simillar to my question but that wasn't answered.
thank you a lot.
any help would be appreciated.