Skip to content Skip to sidebar Skip to footer

How To Get Two Different Results On Startactivityforresult Using Click Listener From The Same Button?

I'm making an android app and I'm using startActivityforResult on click listener. So it is opening the other activity and from there, result will get back to the first activity. No

Solution 1:

you should use on the first activity: onActivityResult() and use the codes and data you've sent from the second activity

Solution 2:

When you send the data change the REQUEST_CODE for the 3 different intent call. like ->

int REQUEST_CODE_1 = 1010;

ll.setOnClickListener(new View.OnClickListener() {
        @Override
        publicvoidonClick(View v) {
            Intent i=new Intent(publishNewBook.this,selectionActivity.class);
            Intent(publishNewBook.this,selectionActivity.class);
            startActivityForResult(i,REQUEST_CODE_1);


        }
    });

when you return from second activity you just check the REQUEST_CODE . Like ->

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {

        if(requestCode == REQUEST_CODE_1){
            // so , do action for button 1 click back.
        }
    }

Solution 3:

From your main activity you call startActivityforresult passing the intent you want to start and a requestcode uniquely marking this request, starting activitytwo. In activitytwo you setresult passing resultcode and optionally an intent containing any data then call finish. Now mainactivitys onactivityresult callback method will be called giving requestcode, resultcode and the optional intent (or null in the case of no return data). The only confusion I can see is maybe you have two or more of these things in that case uniquely identify requestcode in each and "if" them or "switch case"

Post a Comment for "How To Get Two Different Results On Startactivityforresult Using Click Listener From The Same Button?"