FLAG_KEEP_SCREEN_ON not undimming the screen - android

I'm using the following line of code on the onCreate() methods of my two activities:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
The point of course, is to keep the screen turned on and undimmed.
The point is that if the screen is dimmed -not turned off- before one of my activities is launched, the screen will maintain it's dimming until the user touchs the activity. After the user interacts in any way (TouchEvent or something like that, I'm assuming) with the activity the device will undimm the screen and maintain it that way until the user leaves the activity.
Does anyone knows why this is happening and how can I undimm the screen of the device before setting the FLAG_KEEP_SCREEN_ON flag?

Related

How to Keep Screen On For specific condition, even after we left that activity(window)?

Using getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON), It can only allow for one activity. If I switch to another activity than screen will goes off.
My requirement is : If toggle button enable - screen will not off, if disable screen can goes off THROUGHOUT the application.
WAKE_LOCK is not recommended for android 11 and 12 as of now so rather than this options are welcome.
Thank you in advance.

prevent activity from receiving touch events when screen display is off

I'm setting my screen to be always awake in order to preventing it from going into sleep mode at all.
hence, when the screen display is turned off, the user has to touch the screen in order to bring it on again, but the problem is that this touch is received by the foreground activity and it reacts according to it, and the user is for sure just trying to turn the screen display on.
I tried to set the following flags but didn't work:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
&&
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
To resolve your issue you have to do one of the below things which prevents screen to turn off automatically.
Add android:keepScreenOn="true" to some widget in your layout XML resource for this activity. So long as that widget is visible on the screen, the screen will not turn off automatically.
OR
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
to disable the screen timeout and
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
to re-enable it.

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?)

Get access of launcher screen while showing activity content?

is it possible to get touch access of launcher while showing activity?
while activity covering only quarter of screen area only.
as i said make an activity layout which cover quarter area of screen, I added flag for activity getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT);
it works :) to get access of launcher screen, even my activity is open. I notice another one thing i m not able to get click event on launcher, nor getting focus from my activity to launcher, it's just giving me touch event on launcher.
any one have idea over this, how can i get focus from my activity to launcher or any open application.

Wiping Activity stack

I'm implementing a not-so-standard navigational menu that is accessible from every screen in my app. That is to say, from every screen in my app, I can pop up a menu that will let me choose an entirely different area of the app to navigate directly to.
I have several screens that I call edit screens. They are screens where the user had chosen an item from a list of items and are able to then edit the data for that item. I do not wish for these screens to remain on the Activity stack if the user then uses the menu to navigate to some other area of the app.
This is easy enough. I can simply call "finish()" before navigating away. However, there are a couple places where it is possible to access a nested edit screen. Meaning the edit screen the user is currently on is a child of a parent edit screen. I want both off the Activity stack.
Can anyone think of a slick way to do this? The only way I can think of is to always use startActivityForResult and pass back some identifier that tells the screen to kill itself the next time it resumes.

Categories

Resources