Android的完成活动,并开始一个又一个Android

2023-09-12 04:31:14 作者:庸俗且孤独

我很好奇一件事。我要如何完成我的当前活动并启动另一个。

I'm curious about one thing. How can I finish my current activity and start another one.

例如:

MainActivity --(starts)--> LoginActivity--(if success starts)-->SyncActivity--(if success start)-->MainActivity (with updated data).

所以,我想,当 SyncActivity 启动 MainActivity 后succesfull同步,如果我preSS后退按钮不返回 SyncActivity 或其它任何活动之前打开 SynActivity

So I want when SyncActivity starts MainActivity after succesfull sync and if I press back button not to return to SyncActivity or any other activity opened before SynActivity.

我试过这个code:

Intent intent = new Intent(Synchronization.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
this.finish();

但它不能正常工作。任何想法如何让事情正常工作?

but it's not working properly. Any ideas how to get the things to work properly?

推荐答案

使用

Intent intent = new Intent(SyncActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);