Android的 - 杀死注销所有活动 [英] Android - Kill all activities on logout

查看:130
本文介绍了Android的 - 杀死注销所有活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击注销在我的申请,我希望他们能够在我的应用程序带到登录活动,并杀死所有正在运行或暂停活动。

When a user taps "Logout" within my application, I would like them to be taken to the "Login" activity and kill all other running or paused activities within my application.

我的应用程序正在使用的共享preferences可以绕过推出的登录活动,如果用户已登录previously。因此,FLAG_ACTIVITY_CLEAR_TOP不会在这种情况下工作,因为登录活动将在活动堆栈的顶部,当用户拍摄有

My application is using Shared Preferences to bypass the "Login" activity on launch if the user has logged in previously. Therefore, FLAG_ACTIVITY_CLEAR_TOP will not work in this case, because the Login activity will be at the top of the activity stack when the user is taken there.

推荐答案

您可以使用一个BroadcastReceiver监听你的其他活动杀信号

You could use a BroadcastReceiver to listen for a "kill signal" in your other activities

<一个href="http://developer.android.com/reference/android/content/BroadcastReceiver.html">http://developer.android.com/reference/android/content/BroadcastReceiver.html

在你的活动,你注册一个BroadcastReceiver

In your Activities you register a BroadcastReceiver

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("CLOSE_ALL");
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    // close activity
  }
};
registerReceiver(broadcastReceiver, intentFilter);

然后你只需发送一个广播,随时随地在你的应用程序

Then you just send a broadcast from anywhere in your app

Intent intent = new Intent("CLOSE_ALL");
this.sendBroadcast(intent);

这篇关于Android的 - 杀死注销所有活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆