pratik agarwal
pratik agarwal

Reputation: 9

How to add Broadcast in Android?

I want android to notify me of an app launch by sending a broadcast whenever there is a launch. Where to put the broadcast? I don't want to poll continuously and look for changes in the list of running apps.

Upvotes: 0

Views: 31

Answers (1)

Sergey Emeliyanov
Sergey Emeliyanov

Reputation: 6991

Sending a Broadcast is as easy as few lines of code. Just pass an Intent object with with sendBroadcast() method:

Intent intent = new Intent();
intent.setAction("com.example.Broadcast");
intent.putExtra("MyData", 1000);
sendBroadcast(intent);

Upvotes: 2

Related Questions