Java – save the data in the clip in the screen rotation in Android

Can anyone help me solve my problem?

I have one activity and six clips

A clip contains a link to my mediaplayer class, which I use to display some videos in the clip I get the link of each fragment class in the oncreate () method of the activity Every time the screen rotates, the oncreate () method is called and new links to my six fragment classes (and the new mediaplayer) are obtained

Can I save each fragment class linked to me before rotation and restore it? (for example: I save links to my clips by linking to media player classes, then call my MediaPlayer's stop () method, and then when the screen rotates, I restore all data, my MediaPlayer and call ResumePlay () method.

Or this is a bad idea. I need to recreate the link every time. The only thing I need to do is save the video and path of the current time in the onsaveinstancestate file, then restore it to onrestoreinstancestate, and start a new mediaplyer recovery at any time?

thank you!

Solution

For each class extending fragment in the app store, keep its value when you change the screen direction in the onsaveinstancestate method and then keep it in the oncreateview method

For example, for a video problem you encounter, you can do the following:

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("cp",videoview.getCurrentPosition());  
 }

Then keep it like this

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
    if(savedInstanceState!=null)
    {
        int a=savedInstanceState.getInt("cp");
        videoview.seekTo(a);
    }

//the rest of your code then....
}

I hope I can get you

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>