Android Question How to create a picture-in-picture

nedium

Active Member
Licensed User
Longtime User
Hello everyone and thank you for your help.

I wanted to know how I can execute this example from this thread. I want to use a webview, this code destroys and restarts the activity. I don't know if there is any way to store what is being seen for the last time or if there is a way to not destroy the activity.

thank you

Example

SetActivityAttribute(YourActivity, android:resizeableActivity, "true")
SetActivityAttribute(YourActivity, android:supportsPictureInPicture, "true")


Example code:
Sub Label1_Click
    Try
        Dim jo As JavaObject
        jo.InitializeContext
        jo.RunMethod("pip_activity", Null)
    Catch
        Log(LastException)
    End Try
End Sub

#If JAVA
    import android.os.Build.VERSION;
    import android.view.View;
    import android.widget.Toast;
        
    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
        try {
            if (isInPictureInPictureMode) {
                Toast.makeText(this, "in picture in picture mode.", Toast.LENGTH_SHORT).show();
            } else {           
                Toast.makeText(this, "out of picture in picture mode.", Toast.LENGTH_SHORT).show();       
                        
            }
        } catch (IllegalStateException e) {
            e.printStackTrace();
         }
    }   
    
    public void pip_activity(){     
     try {
        if (VERSION.SDK_INT >= 26) {
             this.enterPictureInPictureMode();
         }
     } catch (IllegalStateException e) {
        e.printStackTrace();
     }
    
    return;
    }
#end if
 

drgottjr

Expert
Licensed User
Longtime User
this is supposed to stop recreating the activity:
B4X:
SetActivityAttribute(Main, android:configChanges, "screenSize|smallestScreenSize|screenLayout|orientation")

it seems to work on android 12 but not on android 15. at least in my case.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…