如何在活动中传递onActivityResult数据?

时间:2016-03-21 09:02:07

标签: android onactivityresult

playlistId

如何在onCreate()方法中发送$.each(results, function(index,value) { html += '<ol><li><a data-video- type="https://www.youtube.com/embed/' + value.id.videoId + '?autoplay=1"> <img src="' +value.snippet.thumbnails.medium.url + '">' + value.snippet.title + '</a>)</li><ol>'; }); $('#results').html(html); 值?

2 个答案:

答案 0 :(得分:3)

<强> ResultActivity:

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

获得结果:

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

您不必创建新的Bundle,只需从&#34; Intent数据&#34;中获取额外的内容。 希望这会有所帮助。

答案 1 :(得分: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 );