Java 在重新启动应用程序之前删除所有活动。

Java 在重新启动应用程序之前删除所有活动。,java,android,Java,Android,有人知道我是如何在主启动活动中设置标志的吗?我希望所有活动都将从堆栈中删除 这是我的代码,我知道,但它不起作用: /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Intent mainIntent = new Intent(this, Main.class); mainIntent.setFl

有人知道我是如何在主启动活动中设置标志的吗?我希望所有活动都将从堆栈中删除

这是我的代码,我知道,但它不起作用:

/** 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,但似乎不起作用…

AndroidManifest.xml更新,如下所示

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

为什么在onCreate中调用setFlags?在我看来,当你开始新的活动时,应该叫它。你能告诉我更多关于你想做什么的细节吗?也许我能帮上忙。这是我应用程序的初始屏幕。在应用程序启动之前,我会检查是否有互联网连接。如果没有internet连接,则会出现一个对话框,用户可以退出应用程序。但是,如果之前已使用internet打开应用程序,并且用户在“无internet”对话框中单击“关闭”按钮,则之前的活动将显示:S如果关闭按钮I use system.exit0;我希望您理解我的问题是:
            Intent intent = new Intent(this,Main.class);
            intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
            startActivity( intent );