package com.example.user.myapp; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } /** Called when the user taps the Send button */ public void sendMessage(View view) { EditText editText1 = (EditText) findViewById(R.id.ipAddress); String ipAddress = editText1.getText().toString(); EditText editText2 = (EditText) findViewById(R.id.port); int port = Integer.parseInt(editText2.getText().toString()); EditText editText3 = (EditText) findViewById(R.id.ref); int ref = Integer.parseInt(editText3.getText().toString()); EditText editText4 = (EditText) findViewById(R.id.count); int count = Integer.parseInt(editText4.getText().toString()); GlobalState state = (GlobalState) getApplicationContext(); state.setIpAddress(ipAddress); state.setPort(port); state.setCoilRef(ref); state.setCoilCount(count); Intent serviceIntent = new Intent(this, MyIntentService.class); serviceIntent.setAction("read.coil"); serviceIntent.putExtra("extra.ip.address", ipAddress); serviceIntent.putExtra("extra.ip.port", port); serviceIntent.putExtra("extra.ref", ref); serviceIntent.putExtra("extra.count", count); serviceIntent.putExtra("extra.intent.name", "readCoil8192"); this.startService(serviceIntent); Intent nextIntent = new Intent(this, DisplayMessageActivity.class); this.startActivity(nextIntent); } }