清除活动堆栈。首先运行活动 [英] Clearing activity stack. First run activities
问题描述
我有一个启动这样在首次运行导入流应用程序:
I've got an application that launches an introduction flow on first run like this:
第一次运行
答:介绍文字
A:使用条件
C:选择语言
所有这些步骤都完成后,应用程序设置一个first_run属性设置为false,并启动活动的 D
After all these steps have been completed, the application sets a first_run attribute to false and launches activity D.
现在,我想要做的是要么清除活性堆栈,这样当用户presses后退按钮它返回到主屏幕,而不是活动的 C ,然后当应用再次启动它直接到活动的 D
Now, what I want to do is either clear the activity stack so that when the user presses the back button it goes back to the Home screen rather than activity C and then when the application launches again it goes straight to activity D.
这是我怎么会去这样做任何想法?
Any ideas on how I would go about doing this?
修改
我知道,调用完成()上的每一项活动从堆栈中删除。但我真正的问题是,如果用户希望从回去的乙为 A 也不会工作,如果我已经呼吁的 A完成() 。对不起,不指定这点。
I'm aware that calling finish() on each activity removes it from the stack. But my real problem is that if the user wants to go back from B to A it won't work if I've already called finish() on A. Sorry for not specifying this earlier.
推荐答案
这是肯定的,道歉过去后要去工作。
后来我才意识到这是它不会工作。
This is gonna work for sure, apologies for the last post. I realised it later that it wont work.
在活动A,B和C用途:
In Activity A, B and C use:
BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("ActivityA", "finishing A");
finish();
}
};
@Override
protected void onDestroy() {
unregisterReceiver(myReceiver);
super.onDestroy();
} // This is mandatory to unregister the receiver, else error occur
在这些活动中的onCreate,添加:
In onCreate of these activities, add:
IntentFilter myFilter = new IntentFilter("finish_my_activities");
registerReceiver(myReceiver, myFilter);
在活动D,在那里你想结束这一切:
In activity D, where you wanna finish all this:
sendBroadcast(new Intent("finish_my_activities"));
//Where ever you wanna finish those activities
这篇关于清除活动堆栈。首先运行活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!