MaxChinni
MaxChinni

Reputation: 1216

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()

Upvotes: 5

Views: 4081

Answers (1)

HitOdessit
HitOdessit

Reputation: 7286

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();

Upvotes: 4

Related Questions