Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Switching between two activities and sharing information between them

This is a basic question but I need some help with it.

I have two activities : actA, actB. While in actA I want to start actB and give it a String, than I want to end actB and return another String to actA (I don't want to go to onCreate() of actA, I would much rather return this value to some method in actA so it can use the String from actB.

Help is appreciated

like image 499
Belgi Avatar asked Jan 20 '26 11:01

Belgi


1 Answers

From A.java:
Intent myintentB=new Intent(A.this, B.class).putExtra("<StringName>", "Value");
    startActivityForResult(myintentB, 3);

    from B.java:

    Intent myintentA=new Intent(B.this, A.class).putExtra("<StringName>", "Value"); 
    finish();
    setResult(3, myintentA);


    In A.java
@Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            String result_string=data.getStringExtra("<StringName>");
        }
like image 186
Pinki Avatar answered Jan 23 '26 01:01

Pinki