Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

android - How to return a result through multiple activities

in some part of my application there is a structure of activities like this:

enter image description here

Activity A is my home activity where I come back after each process or flow.
Activity B is a simple confirmation activity.
Activity C is another confirmation activity.
Activity D does some process and finally it gets back the result to my home activity (Activity A).

Requirements:

Activity B and C:

  • must be there and cannot be merged in one.
  • when it is clicked on the cancel button it calls finish() and does nothing.
  • when it is clicked on the OK button it follows the flow and the current activity calls finish()

Question:

I was thinking about using startActivityForResult() but I have never used it to pass a result through multiple activities..
I also was thinking to pass a handler (created in Activity A) which calls some method on Activity A and is executed on Activity D...

How could I implement it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You might like to make use of the intent flag FLAG_ACTIVITY_FORWARD_RESULT as described in Intent when starting activities B and C

public static final int FLAG_ACTIVITY_FORWARD_RESULT

Since: API Level 1

If set and this intent is being used to launch a new activity from an existing one, then the reply target of the existing activity will be transfered to the new activity. This way the new activity can call setResult(int) and have that result sent back to the reply target of the original activity.

That way A should pick up any data sent back in the extras sent back from D


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...