My application can be launched in two ways. 1. Manual launch. (By clicking the launcher icon from the launcher menu) 2. Automatic launch(By connecting the USB cable to the device)
The application can be finished in two ways. 1. Manual finish (Pressing the back button) 2. Automatic finish (Disconnecting the USB cable)
I have written a broadcast receiver and it will launch the application if USB cable connects.
Now i am finishing my activity by registering the action "android.intent.action.ACTION_POWER_DISCONNECTED"
in the activity itself. It is working fine. My problem is when the user disconnects the usb cable while the device in locked state activity is not getting finished. The broadcast receiver written in the activity is not able receive the action but i can receive the action in the broadcast receiver. I am not able to finish the activity from the broadcast receiver.
What i am doing is made boolean variable true in the broadcast receiver and checks in the onResume() of the activity and trying to finish the activity from onResume(). It is also not working. Is there any solution.
It is fixed now. I was registering the receiver in onResume() and unregistering it in onPause(). So i wont get the action of Disconnecting the usb cable when the device in locked state. Because the application will go to onPause() when the user lock the device. Now i am registering it in the onCreate() and unregistering from onDestroy() so it is working. cheers!!!