0

I have class that is declared in MainActivity:

public class MainActivity extends ListActivity {

 public class CommunicatorServiceImpl implements CommunicatorService{

    @Override
    public Communicator createCommunicatorThread(BluetoothSocket socket) {
        return new CommunicatorImpl(socket, new CommunicatorImpl.CommunicationListener() {
            @Override
            public void onMessage(final String message) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        textData.setText(textData.getText().toString() + "\n" + message);
                    }
                });
            }
        });
    }


}

private final CommunicatorService communicatorService = new CommunicatorServiceImpl();

}

I need to transfer communicatorService to the service. This object, along with the service, will use the thread. As I know, I can't transfer an object as an argument of the service constructor. How can I do this?

Thanks in advance.

Andrew Efremov
  • 423
  • 5
  • 12
  • Not really. I need to transfer an object to the service. This object, along with the service, will use the thread. – Andrew Efremov Jun 30 '17 at 09:41
  • Read the post I linked. It'll give you options to get the object to the service, by for example using a singleton pattern. – Tim Kranen Jun 30 '17 at 10:05

0 Answers0