Android的移动回第一项活动按钮点击 [英] Android moving back to first activity on button click
问题描述
我写在那里我处理4活动的应用程序,假设A,B,C和; D.活动A调用B,B调用C,C调用D.在每一个活动,我有一个叫做家的按钮按钮。当用户在任何的B点击home键,C,D活动,应用程序应该回到A活性屏?
如何模拟在这种情况下,家按钮?
button.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
startActivity(新意图(贵方寄去化妆品,的A.class));
}
});
声明一个在你的清单与安卓launchMode =singleTask
。这样,当你调用 startActivity()
从其他activies,而A已经在运行,它只是把它的前面。否则,它会启动一个新的实例。
I am writing a application where I am dealing with 4 activities, let's say A, B, C & D. Activity A invokes B, B invokes C, C invokes D. On each of the activity, I have a button called "home" button. When user clicks on home button in any of the B, C, D activities, application should go back to A activity screen ?
How to simulate "home" button in this case ?
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(D.this, A.class));
}
});
Declare A in your manifest with the android:launchMode="singleTask"
. This way, when you call startActivity()
from your other activies, and A is already running, it will just bring it to the front. Otherwise it'll launch a new instance.
这篇关于Android的移动回第一项活动按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!