0

How to logout my android application automatically when mobile getting shutdown?
I want to stop or close or logout my android application which in running in background in android when mobile getting is shutdown.

Is it possible? If so how to achieve this?
Any links will be appreciated.

Tomas Jablonskis
  • 4,246
  • 4
  • 22
  • 40

3 Answers3

1

You need to listen for the following intent actions in your receiver/service:

<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />

For more info, read this.


Hope this helps. Good luck :)

Tomas Jablonskis
  • 4,246
  • 4
  • 22
  • 40
1

Have a broadcast listener for

 <action android:name="android.intent.action.ACTION_SHUTDOWN" />
 <action android:name="android.intent.action.QUICKBOOT_POWEROFF" />

and in onReceive perform logout action

You can also use ACTION_BOOT_COMPLETED receiver which will notify when phone booting is completed

Manohar
  • 22,116
  • 9
  • 108
  • 144
1

Try this!

public class ReceiverForPowerOff extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //Insert code here for logout
    }

}

In manifest:

<receiver android:name=".ReceiverForPowerOff">
  <intent-filter>
    <action android:name="android.intent.action.ACTION_SHUTDOWN" />
  </intent-filter>
</receiver>
Tara
  • 692
  • 5
  • 23