Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the name of a service class in Android?

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()
like image 740
MaxChinni Avatar asked Oct 07 '22 10:10

MaxChinni


1 Answers

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();
like image 173
HitOdessit Avatar answered Oct 10 '22 10:10

HitOdessit