I have a MyServiceClass defined as follows:
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}
If I call startService(new Intent(getBaseContext(), MyService.class));
from an activity class in the same package/app/APK, then I can see the Toast
message.
But if I put this class in an application with no activity whatsoever (that is, service-only application) by simply tying it to boot receiver:
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, com.example.tutorialspoint7.noactivity.MyService.class));
}
}
Then, when the service starts, I no longer see the message.
I can restart the service on demand via Package Browser
:
I understand that if there is no activity to provide a UI, then those messages don't really have where to be displayed. My questions, though, are:
- Is there a default place where I can find these messages? (e.g. log file, buffer, LogCat, etc.)
- Can I redirect these messages to the home screen current screen?
- Why isn't the Android Studio framework display a warning when it sees/builds an APK that contains Toast.makeText().show() messages that have nowhere to be displayed?