开发者

StartActivityForResult

I have 4 activities A,B,C,D. I need to start activity 'A'(It Consists of a textview,button) initially and from activity 'A' i need to start activity 'B'(With the help of a button).

Now,From 'B' i need to start 'C' & 'D' activities (Condition: Button1(Activity 'B') is hit then it should start Activity 'C' , Button2(Activity 'B') is hit then it should start Activity 'D' ).

--Activity 'C' consists of a EditText & a Button. --Activity 'D' consists of a EditText & a Button.

Here when i enter te开发者_运维百科xt in Edit text of Activity 'C' & 'D' and hit the Button,the result is such that the entered text should appear in TextView of Activity 'A'.

Iam a Beginner to Android,Ple help me in getting through this. Thanks in Advance.


Try this: make a static variable in Activity 'C':

public static String text="";

then read EditText data into String in OnClick of button :

in your Activity'C' on button click:

text=edittext.getText().toString();
 Intent i=new Intent(ActivityC.this,ActivityA.class)
 startActivity(in);
 finish();

In Activity 'A'

set this text value in OnResume method:

Protected void OnResume()
{
super.OnResume();
textview.setText(Activity'c'.text)
}

this may help you.ask any doubts


So you are wanting to pass data from Activity C, or D back to A at some point? Use an application class (google it) and set a variable from your C or D Activities, then call said variable when you get back to A and display the text.


Using `startActivityForResult() you can do like this :

  1. startActivityForResult() for activity B.
  2. startActivityForResult() for activity c.
  3. On button hit in activity c finish the activity after setting the data.
  4. now you will get call in onActivityResult() in activity B. repeat the process of setting data in B and finish the activity.
  5. now you will get call in onActivityResult() in activity A, you got the data now use it.

same process will be for activity D.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜