Question

I'm printing the right id out from the first intent but not sending to it the second intent properly.

first intent on item click: (For later viewers this question has been updated with the correct answer):

    gridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> a, View v, int i, long l) {

            Intent intent = new Intent(videoChannelActivity.this,
                    PlayVideoActivity.class);
            intent.putExtra("videoId", l);
            System.out.println("video id intent1 = " + l);
            startActivity(intent);
        }
    });

log: 05-08 17:40:40.505: I/System.out(13938): video id intent 1: 2

second intent on create:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final VideoView videoView;

    setContentView(R.layout.activity_play_video);

    Bundle extras;
    long videoLong;

    if (savedInstanceState == null) {
        extras = getIntent().getExtras();
        if (extras == null) {
            videoLong = 0;
        } else {
            videoLong = extras.getLong("videoId");
            System.out.println("video id intent 2 =  " + videoLong);
        }
    }

log: 05-08 17:46:19.166: I/System.out(14382): video id intent 2 = null

Was it helpful?

Solution

l is type of long ...

so you need to extract long instead of String like

 videoLong = extras.getLong("videoId");

so the full implementation of second intent is

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final VideoView videoView;

    setContentView(R.layout.activity_play_video);

    Bundle extras;
    Long videoLong;

    if (savedInstanceState == null) {
        extras = getIntent().getExtras();
        if (extras == null) {
            videoLong= null;
        } else {
            videoLong= extras.getLong("videoId");
            System.out.println("video id intent 2 =  " + videoLong);
        }
    }

OTHER TIPS

You're passing a long as an extra but trying to read it as a String.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top