How to use a class method on an Activity?

Asked

Viewed 144 times

0

I need to use the following method, which is located in the Vodplayeradapter class in an Activity Playeractivity:

 public void changeVideo(Video video, boolean playWhenReady) {
    finalizePlayer();
    this.video = video;
    VodSource.getInstance().getImageLoader().get(VodSource.URL_SERVER + this.video.getThumb(), new DescriptionImageListener(thumb));
    if(playWhenReady) {
        startVideo(playWhenReady);
    }
    else {
        rebuildThumb();
    }
}

This class that is abstract is instantiated twice, one in Playlistactivity, that interests me, in this way:

vodPlayerAdapter = new VodPlayerAdapter(view, video, getWindow(), VodPlayerAdapter.PLAYLIST_MODE, true) {
        @Override
        public void refreshVideoInfor() {
            refreshVideoInfo();
        }
    };

The above method is in Playlistactivity which calls Playeractivity. When I click on a button, it terminates Playlistactivity, and at this point initializes Playeractivity... In Playlistactivity I create an instance of the object of my class Vodplayeradapter, I can use its methods etc, but in this other Activity I can no longer, and because it is an Adapter with information of the previous state that was in Playlistactivity, I don’t think I can give it new again just to use where I want, even tried and it’s wrong. That way, I would like to know some way that could use this method of the class Vodplayeradapter in Playeractivity without creating new instance.

1 answer

0

If you only want to use the method, please instate a class you inherit from VodPlayerAdapter, implement the method in this way

@Override
public void refreshVideoInfor() {
      refreshVideoInfo();
}

And install this class both in PlaylistActivity and PlayerActivity. Both will run the same method. If the problem is the parameters, pass them appropriately from PlaylistActivity for PlayerActivity and pass them on this daughter class of VodPlayerAdapter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.