Android的完成活动,并开始一个又一个 [英] Android finish Activity and start another one

查看:134
本文介绍了Android的完成活动,并开始一个又一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

这篇关于Android的完成活动,并开始一个又一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆