如何关闭我的应用程序的所有活动? [英] How to close all the activities of my application?
本文介绍了如何关闭我的应用程序的所有活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个活动的应用程序,例如:
I've got an application with several activities, for example:
活动1 - >活动2 - >活动3 - >活动4
Activity 1 --> Activity 2 --> Activity 3 --> Activity 4
和我想从任何活动关闭所有的活动,回到家里的电话。
And I would like to close all the activities from any activity and go back at home phone.
推荐答案
可以实现通过使用 BroadcastReceivers
:
- 创建一个
BaseActivity
是这样的:
- Create a
BaseActivity
like this:
public class BaseActivity extends Activity {
private KillReceiver mKillReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mKillReceiver = new KillReceiver();
registerReceiver(mKillReceiver,
IntentFilter.create("kill", "spartan!!!"));
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mKillReceiver);
}
private final class KillReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
finish();
}
}
}
- 请你的活动延长了
BaseActivity
。 - 每当你想清除栈:
- Make your activities extend that
BaseActivity
. - Whenever you want to clear the stack:
Intent intent = new Intent("kill");
intent.setType("spartan!!!");
sendBroadcast(intent);
这篇关于如何关闭我的应用程序的所有活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文