2
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 900) {
        if (resultCode == getActivity().RESULT_OK) {
            Bundle b=data.getExtras();
            if(b!=null){
                Playlist playlist = (Playlist) b.getSerializable("obj");
                int playlistId = data.getIntExtra("PLAYLIST_ID", 0);

                Log.d("---->Data ID", String.valueOf(playlistId));
            }
        }
    }

How can I send that playlistId Value in onCreate() method?

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57

2 Answers2

4

ResultActivity:

  intent.putExtra("yourKeyName", "hello");
    setResult(900, intent);

Get the result:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode== 900) {
        if (resultCode == getActivity().RESULT_OK) {
            String hello = data.getStringExtra("yourKeyName");  
        }
    }

You dont have to create a new Bundle, just get extra content from the "Intent data". Hope this helps.

Fabio Venturi Pastor
  • 2,519
  • 3
  • 19
  • 32
  • Is it posssible to access hello somewhere out of onActivityResult after setting it? For example, what if it was required to pass hello to another activity. – StudentOfTheGame Nov 15 '22 at 13:18
0
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode== 900) {
        if (resultCode == getActivity().RESULT_OK) {
            Bundle b=data.getExtras();
            if(b!=null){
                Playlist playlist = (Playlist) b.getSerializable("obj");
                int playlistId = data.getIntExtra("PLAYLIST_ID", 0);

                Log.d("---->Data ID", String.valueOf(playlistId));
            }
        }
    }

use this in another activity to get the result back 

Intent intent = new Intent();

intent.putExtra("key",value);
setResult(900,intent );
Rohit Heera
  • 2,709
  • 2
  • 21
  • 31