How do I get the name of a service programmatically in Android?
Let's say I've this piece of code:
public class MainActivity extends Activity {
private MyService mService;
Let's say I want to toast the name of the service which could be like com.example.MyService
.
Is it possible to get it from mService
variable?
For now, I got it using MyService
in this way
MyService.class.getName()
If you want to get class name dynamically, you can use:
mService.getClass().getName();
If you want to get class name only, without package, you can use:
mService.getClass().getSimpleName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With