How to Start Activity with Picture-in-Picture mode directly in Android - android

I have to open activity directly on picture-in-picture mode like WhatsApp playing video in chats.
I tried but it launches activity normally and when I click button and apply the code for entering into picture-in-picture mode only it is working.
I need without clicking any button directly launch the activity on picture-in-picture mode
<activity
android:name=".PiPActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:label="#string/title_activity_pi_p"
android:launchMode="singleTask"
android:resizeableActivity="true"
android:supportsPictureInPicture="true"
android:theme="#style/AppTheme.NoActionBar" />
Starting from MainActivity:
startActivity(new Intent(this, PiPActivity.class).putExtra("videoUrl", model.videoUrl));

As far as I know, an activity can not be opened directly in picture-in-picture (pip) mode. It will be first opened as a normal activity only. However, if you want it to go to pip mode as soon as it is launched, you can call enterPictureInPictureMode(yourParamsToBePassed) inside onCreate() or onStart() or onResume() lifecycle callbacks.
WhatsApp playing video in chats
It does not seem like, WhatsApp uses pip mode to launch the video. It is most probably a custom layout (which looks like a PIP view). This can be proven by the fact that this pip-look-alike-layout is not the topmost view of the screen. If you try moving this pip-look-alike-layout, it will be hidden behind ChatNameBar and TypeMessageBar. Basically, its elevation is lesser than those two. This contradicts the fact that the pip view is shown on top of all the running activities/apps.

Related

How to make a popup activity?

I want to make an activity that when called appears as a small popup on top of any current app (or home screen) kinda like google assistant usually does when called. It is intended to ask for a fingerprint input for 3 seconds or hide if user touches outside its window.
Google assistant is service not any popup activity.
you can do popup activity but, it will only work for when app in foreground like google assistant need background service.
you can use theme
android:theme="#android:style/Theme.Holo.Light.Dialog.MinWidth" for activity make like pop dialog. for this theme require activity instead of appcompatactivity.
if you want exclude from recent use in manifest android:excludeFromRecents="true"
<activity
android:name=".ActivityName"
android:excludeFromRecents="true"
android:label="#string/app_name" />

How to force activity always appear in portrait orientation without delay in lockscreen?

I have an activity with "portrait" orientation in AndroidManifest.xml.
When I start it from lock screen in landscape orientation, it appear with landscape for 1 second, and then change to portrait. The delay happens even if it's an blank activity (no view, no task).
Tell me how to avoid this delay. Remove transition effect, rotation effect? I know it could be device performance, but still want to fix this.
If you always wants to run your app in landscape mode than use this code in Manifest file for all activity
<activity
android:name=".yourAcitvity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"
/>
That't the default behavior of Android, you can verify this issue using system apps. For ex: open the Android's default messenger, and turn it to landscape and lock the phone, now unlock it and you can see the messenger has re aligned to portrait, that's because the home screen is set to portrait by default. In order to show the home screen the system aligns the device to portrait again.

Android: How to Enable Samsung Multi-Window in Only One Activity

I have got the multi-window feature to work however, this is applied to all activities across the application. I would like to know is there a way to specify which activity that can use multi-window? For example, I have an introduction slider in which I would like to disable the feature and re-enable in the main activity. Thanks.
By launching activity in new task stack, you can accomplish this. But from user experience point of view, this may not be a good solution.
When app is in split screen mode, launch the activity, which you don't want do display in multi-window mode, by firing intent. Make sure that the target activity config in manifest is not multi-window enabled.
To go back to multi-window mode from full screen, you need to launch main activity in a new stack with below intent flags.
FLAG_ACTIVITY_LAUNCH_ADJACENT and FLAG_ACTIVITY_NEW_TASK

Changing Activity screen when the app is not running

How can i change the screen of an activity when pressing any button on an android phone that takes one away from the running app.
I'm trying to get a blank screen to show up on the "recents" screen, instead of a snapshot of the app.
You can use this option and check if it helps you meet your need.
android:excludeFromRecents="true"
Add this to your activities in the application manifest if you do not want the app to be shown in the recent apps list. One drawback is that you would not be able to resume the app from the Recents list. Not sure if this is what you need.
The other way is to have a 'Blank Activity', which you start when your actual activity pauses. You can then finish the 'Blank Activity' on its Resume. This way, you will have your app shown on the Recents list, but with a blank screen.
You can call finish() for activity but that will kill activity. I think that will leave blank screen. Or destroy(). Try both respond with results.
you might want to change the onpause() or onclose() functions of your app. they are the last thing android execute before leaving,therefor you can change the aspect off your app just before you leave it
EDIT :
Maybe if you create PopupWindow and set it to full screen, and color black when exiting no preview would be shown, but app would still be running (idea of user DjDexter5GH) in the onpause() and onclose() functions. therefgor,when you leave,a black(or whatever you want) screen is pushed in front
you can then close it in the onrestart(is it called this?)

On ICS devices Current Activity disappearing when screen gets locked

In activity manifest file i have marked it as android:noHistory="true" because I did not want the screen to be added to the activity stack.
when I lock the screen and unlock it. The activity disappears and the previous screen appears. This should not happen. Please any one can suggest me, how can i handle this on ICS devices. However its working fine on Gingerbread devices.
Remove android:noHistory="true" in android manifest file and call the finish when you move out of that Activity. This will remove the activity completely from the stack and it will not be displayed in your backstack. I hope this will work for you

Categories

Resources