Intent.FLAG_ACTIVITY_CLEAR_TOP不删除该活动栈 [英] Intent.FLAG_ACTIVITY_CLEAR_TOP doesn't deletes the activity stack
问题描述
我开发的,我想关闭按钮点击整个应用程序的应用。我知道,在Android中,我们不应该考虑到由于Android的自动执行此<一个关闭应用程序href="http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon?lq=1">Quitting一个应用程序 - 这是令人难以接受的?但我却想收我的应用程序。
I am developing the application in which i want to close whole application on button click. I know in android we should not think about to close the application because android does that automatically from this Quitting an application - is that frowned upon?. but yet i want to close my application.
所以我在做什么,收的应用程序是我使用 Intent.FLAG_ACTIVITY_CLEAR_TOP
标志删除活动堆栈。
So what i am doing to close application is i am using Intent.FLAG_ACTIVITY_CLEAR_TOP
flag to delete the activity stack.
Intent intent = new Intent(Activity3.this, FinishActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
和中的onCreate FinishActivity.class
我打电话 this.finish()
,但应用程序不会被关闭和previous活动被重新打开。
And in onCreate of FinishActivity.class
i am calling this.finish()
but application is not get closed and previous activity gets reopened.
FinishActivity.class
FinishActivity.class
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.finish();
}
更新:
下面是该方案
MainActivity->Activity2->Activity3->FinishActivity
下面活性2
是在完成活动后,被打开了。
Here Activity2
is gets opened after finishing the activity.
我如何实现这一目标?任何意见和建议将成为AP preciated。
How do i achieve this? Any idea and suggestion will be appreciated.
感谢和放大器;问候
推荐答案
使用此 -
Intent intent = new Intent(Activity3.this, FinishActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();
编辑 - 新的答案,并会努力perfectelly ..
只是走一个例子......做你的项目需要相应的东西 -
just taking an example...do it accordingly what your project needs--
我服用三Activity类A,B和C..and我已经Activity..If你想要然后通过返回按钮,你可以去到previous活动,当应用在C类的视图关闭按钮您preSS关闭按钮,那么你将退出从apps..have看看 -
I am taking three Activity class A, B and C..and i have applied close button on the view of class C Activity..If you want then by Back button you can go to the previous Activity and when you press close button then you would exit from apps..have a look--
public class AActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent(this, B.class);
startActivityForResult(i, 1);
}
@Override
protected void onActivityResult(final int requestCode,
final int resultCode, final Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == 5) {
finish();
}
}
}
取隔壁班的活动 -
Take next class activity--
public class B extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.b);
Intent i = new Intent(this, C.class);
startActivityForResult(i, 2);
}
@Override
protected void onActivityResult(final int requestCode,
final int resultCode, final Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == 5) {
setResult(5);
finish();
}
}
}
取最后一项活动 -
Take last activity--
public class C extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.c);
}
// close button..set by xml view..you can set it by button listener.
public void close(View v) {
setResult(5);
finish();
}
}
希望能解决您的problem..cheers!
Hopefully it would solve your problem..cheers!
这篇关于Intent.FLAG_ACTIVITY_CLEAR_TOP不删除该活动栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!