I cannot seem to find this anywhere. Here is the issue:
I have a Fragment A that comes from Activity A. This fragment launch Activity B.
I want to send From Activity B to Fragment A. How is that done?
I cannot seem to find this anywhere. Here is the issue:
I have a Fragment A that comes from Activity A. This fragment launch Activity B.
I want to send From Activity B to Fragment A. How is that done?
You can try to use 'startActivityForResult()'. This will start the activity, and then when it's done, it will allow you to return some data to a callback function in the fragment that you override. Here's an example:
private void ActivityBStarter(){
Intent i = new Intent(getApplicationContext(),ActivityB.class);
startActivtyForResult(i);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
//use data.get... to get data from the activity.
//This is only called when the activity completes.
}
Then in the activity, do this when you want to finish the activity and pass the result back:
Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
setResult(RESULT_OK,returnIntent); //RESULT_OK can really be any int you want.
finish();
Alternatively, you could use Messengers and message passing to pass data between your Activity and fragment as ActivityB is running, but that's usually not very useful unless you're using a Service.
Here's a link: Example: Communication between Activity and Service using Messaging
Good luck!