Hello,
I have a class, MyService. This is my Android service. I wanna generate two random numbers, and this service should return the sum of these numbers. How can i do that? So , i should generate the numbers in
public void onStart(Intent intent, int startid) {
//Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
// here i generate the numbers (random) and i compute the sum , nr1+nr2.
}
Then, how can i return the result to the main activity, and display the sum of the numbers as an alert (for example), or in an edit box when a button is pressed? So, in the main class i have
public void onClick(View src) {
switch (src.getId()) {
//start the service
case R.id.buttonStart:
Log.d(TAG, "onClick: starting srvice");
startService(new Intent(this, MyService.class));
break;
case R.id.buttonStop:
Log.d(TAG, "onClick: stopping srvice");
stopService(new Intent(this, MyService.class));
break;
}
The question is how/where can i return the result of that service (that nr1+nr2), and how should i display the result?
Thanks!