2011-08-18 62 views
0

有些知道我如何在主(启动)活动中获取设置标志吗?我希望所有的活动都将被移除。在重新启动应用程序之前删除所有活动。

这是我的代码知道,但它doenst工作:

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
Intent mainIntent = new Intent(this, Main.class); 

mainIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(mainIntent); 

setContentView(R.layout.splashscreen); 

LoadData(); 

}

我也曾尝试使用android:clearTaskOnLaunch,但似乎没有工作...

+0

你为什么要在'onCreate()'中调用'setFlags()'?在我看来,它应该在你开始新的活动时被调用。你能告诉我更多关于你想做什么的细节,也许我可以帮助 –

+0

这是我的应用程序的启动画面。在应用程序启动之前,我检查是否有互联网连接。如果没有互联网连接,则会出现一个对话框,以便用户可以退出该应用程序。但是,如果应用程序以前已经与互联网打开,并且用户单击关闭按钮(在没有互联网的对话框中),则先前的活动出现:S在关闭按钮的情况下,我使用system.exit(0);我希望你明白我的问题是什么:) – Johan

回答

0

的AndroidManifest.xml更新如下所示,

<activity 
     android:name="Main" android:label="Post an Ad" android:launchMode="singleTop"> 

使用以下代码,

  Intent intent = new Intent(this,Main.class); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(intent); 
相关问题