How can i pass string created in main activity to my services ? It was created in editText not strings.xml... I am new to java and I can 't find it...
Thanks
edit//
In main I have:
public class MainActivity extends Activity {
private static final String LOG_TAG = "aktivita" ;
private Button btnStart, btnStop;
public EditText input;
public String filename;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnStart = (Button) findViewById(R.id.btnStart);
btnStop = (Button) findViewById(R.id.btnStop);
btnStart.setEnabled(true);
btnStop.setEnabled(true);
input = (EditText) findViewById(R.id.editTxt);
Log.d( LOG_TAG, "ON CREATE" );
}
public void onStartClick(View view) {
filename = input.getText().toString();
Intent serviceIntentAcc = new Intent(this, accService.class );
startService(serviceIntentAcc);
Intent serviceIntentGyro = new Intent(this, gyroService.class );
startService(serviceIntentGyro);
btnStop.setEnabled(true);
btnStart.setEnabled(false);
Log.d(LOG_TAG, "ON START CLICK");
}
I nned to use filename string in my service ... Here:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
//String FileName = editTxt.getText().toString();
try {
writer = new FileWriter(root + "/" + filename + "acc.txt",true);
} catch (IOException e) {
e.printStackTrace();
}
Log.d(LOG_TAG, "SERVICE - ON START COMMAND");
return START_STICKY;
}
I am new to android and java and I do not understand it very well :/ can someone explain it ? Thanks for being patient.