How to get service class name in Android?

How can I get the service name programmatically in Android?

Say I have this piece of code:

public class MainActivity extends Activity { private MyService mService; 

Suppose I want to fry a service name, which could be like com.example.MyService .

Is it possible to get it from the mService variable?

Currently, I got it using MyService this way

 MyService.class.getName() 
+4
source share
1 answer

If you want to get the class name dynamically, you can use:

 mService.getClass().getName(); 

If you want to get only the class name, without a package, you can use:

 mService.getClass().getSimpleName(); 
+2
source

Source: https://habr.com/ru/post/1437970/


All Articles