As @Squonk already mentioned your code doesn't really go together. To start your Service
you have to use an Intent
like this:
// The class you set here determines where the Intent will go.
// You want it to start MyService so we write MyService.class here.
Intent intent = new Intent(this, MyService.class);
intent.putExtra(Intent.EXTRA_TEXT, "a message");
startService(intent);
You can very well use the Intent.EXTRA_TEXT
constant as key for your extra, but you have to use the same key to retrieve the message in your Service
:
@Override
protected void onHandleIntent(Intent intent) {
String message = intent.getStringExtra(Intent.EXTRA_TEXT);
Log.d(TAG, "received message, should say: " + message);
}
The code in your MyService
doesn't really show if you actually use the mime type in your MyService
so I removed it from my example above.