活动流A-> B-> C->将在android系统 [英] Activity Flows A->B->C->A in android

查看:149
本文介绍了活动流A-> B-> C->将在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有3项活动:A,B和C


  • 答:家庭活动

  • 乙:信息收集活动

  • C:信息显示活动

我所需的流量是这样:


  • 系统会触发B到收集信息。

  • 当B端,C将得到的信息和显示。

  • A-> B-> C->一个。

  • 当C结束,它应该回到A.(这是从来没有因为我将B中的问题:完成())

我的第一次尝试:(失败,原因是我不想看到A B后,甚至几毫秒)

My first attempt: (Failed due to I do not want to see the A after B, even for few miliseconds)


  1. 系统会触发B到收集信息。 (startActivityAsResult)

  2. 乙传球结果a和b:完成()。 (的onActivityResult)

  3. 则A触发C-显示。 (startActivity)

  1. A triggers B to gather information. (startActivityAsResult)
  2. B pass result to A, and B :finish(). (onActivityResult)
  3. Then A triggers C to display. (startActivity)

我的第二次​​尝试:(?成功,但我想有一个更好的办法,尽管这一点)

My second attempt: (Succeed but I'm thinking is there a better way despite this?)


  1. 系统会触发B到收集信息。 (startActivity)

  2. B触发C,和B:完成()。 (startActivity)

  1. A triggers B to gather information. (startActivity)
  2. B triggers C, and B :finish(). (startActivity)

问题:

有没有定义的序列的任何替代方法(这是比较简单/直接)的导航流向像我看到 taskBuilder nextIntent() API?

Is there any alternative way (which is simpler/direct) of defining the sequence of navigation flows like i see taskBuilder with nextIntent() API?

推荐答案

在上后退按钮preSS活动清除C的backstack并导航到A

In Activity C on back button press clear the backstack and navigate to A

 @Override 
 public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
    onBackPressed();

}

return super.onKeyDown(keyCode, event);
   }

    public void onBackPressed() {
Intent myIntent = new Intent(C.this,A.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);// clear the backstack
startActivity(myIntent);
finish();
return;
   }

A到B到C

在你后面的活动栈,你会在顶部,接下来的B和下一个A对C

In your activity back stack you will have C at the top, next B and next A.

在preSS返回按钮C,活性C从堆栈中弹出,破坏和previous b活动需要关注。所以,如果你想从C导航到A,疏通背部栈,导航到并完成当前活动。

When you press back button in C, activity C is popped from stack, destroyed and the previous activity B takes focus. So if you wish to navigate to A from C ,clear the back stack , navigate to A and finish the current activity.

这篇关于活动流A-> B-> C->将在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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