Android: Network Radio off before ACTION_SHUTDOWN event.Events order Changed in ICS-ThrowExceptions

Exception or error:

I was sending logout to my server when user did a power off on the device.The order of events in 2.3 and 4.0.3 are as follows.So now Log out is Failed.

Device : Samsung Galaxy s2

Android : 2.3


2) Send Logout event,sleep for 5 secs,LOG OUT SENT SUCCESSFULLY

3)Data Network Radio off event.

4)Device Power off.

Android : 4.0.3

1) Data Network Radio off event.


3) Send Logout event,LOG OUT FAIL As Network is down.

Any way around to get ACTION_SHUTDOWN before Data Network Radio off?

How to solve:

It doesn’t look like vanilla Android behavior. May be your device’s manufacturer did some internal improvements to the shutdown process to speed it up.

You can see how shutdown is handled at frameworks/base/services/java/com/android/server/pm/ on current master branch.

However as a mobile application developer you shouldn’t rely on constant network connection.


Have you tried using a Service for that? You could register an ever-running service so that when it receives onDestroy() you know your app is being killed and do that logout request.

Just an idea. I don’t know whether service’s onDestroy() gets called earlier than network goes down, but I’d give it a try just in case.


Create a service that receives the broadcast for the shutdown like this:

public class MyAppShutdown extends BroadcastReceiver{
    private static final String TAG = "MyAppShutdown";
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Log.v(TAG, "onReceive - ++ ENTER ++");
        if (intent != null && intent.getAction().equals(Intent.ACTION_SHUTDOWN)){
            Log.v(TAG, "onReceive - ***] SHUTDOWN [***");
            // perhaps send a broadcast to your app via intent to perform a log out.
            Intent intent = new Intent();
        Log.v(TAG, "onReceive - ++ LEAVE ++");        

In your AndroidManifest.xml, embed this fragment below within the <application> tags:

<receiver android:name=".MyAppShutdown">
         <action android:name="android.intent.action.SHUTDOWN"/>

From your app’s activity register a broadcast receiver with the appropriate filter for intents:

public class myApp extends Activity{
    private myAppBroadcastRcvr myAppRcvr = new myAppBroadcastRcvr();
    public void onCreate(Bundle savedInstanceState){
        IntentFilter filter = new IntentFilter();
        registerReceiver(myAppRcvr, filter);
    // Perhaps you have this
    private void LogOff(){
    class myAppBroadcastRcvr extends BroadcastReceiver{
        public void onReceive(Context context, Intent intent){
            if (intent.getAction().equals("intent.myapp.action.shutdown")){

Leave a Reply

Your email address will not be published. Required fields are marked *