In this example detecting current running activity from top of the activity stack. In this way we can find out current running application and task.
Use :
1. Suppose you have a task like , when user opens message/phone call/any application screen then your app performs an action like start a music or vibration etc....
In this example broadcasting screen wake / sleep event with a service.
Some times we have requirement to make less battery consumption then you can stop your services when phone is going to sleep mode and again start your services when phone is going to wake.
Steps :
1. Create a service inside main activity to get screen wake / sleep broadcast events. 2. Create a broadcast receiver inside service to get screen wake / sleep events. 3. Send screen wake/sleep value from broadcast receiver to Service.
In this android example we are showing ,when any new SMS event brodcasted ( When new SMS received ) then how to create receiver to read Incomming SMS data.
In this android example we are showing ,when any new call event brodcasted ( When new call come ) then how to create receiver to read phone call states.
1. A broadcast receiver is an Android component which allows to register and listen for device orientation changes like sms messsage recieved , phone call recieved/pick/cut ,battery status changed, the Wi-Fi came on.
2. Android operating system and even other applications time to time broadcast messages about things that are happening like sms messsage recieved , phone call recieved/pick/cut ,battery status changed, the Wi-Fi came on.
3. With the help of broadcast receiver you will catch Android operating system specific events and then you can code your application for that event.