Black screen is displaying in Android - android

I opened my application after I am not doing any kind of operation. I leave the mobile 5 min. After 5 min when I touch the my application it is showing black screen. Is there any way to avoid this idle state?

This is easy to do. Use: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); in your onCreate method.
There is another way, called a WakeLock, but you really shouldn't use that unless you know what you're doing. See this post from one of the Android designers for more information about WakeLocks and why you shouldn't use them unless you're careful.

Related

In Unity3D how turning off screen whithout sleep?

As in Unity3D turn off the screen without entering sleep mode, so that the application continues to work?
I don't believe it's possible to have Unity run in the background.
I don't know if this is still common practice, but in the past, many people simply draw a fully black screen to conserve power.
See: https://forum.unity.com/threads/application-runinbackground-is-not-working-on-android.117723/
Have you looked at - https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationFocus.html
OnApplicationFocus is called when the application loses or gains focus. Alt-tabbing or Cmd-tabbing can take focus away from the Unity application to another desktop application. This causes the GameObjects to receive an OnApplicationFocus call with the argument set to false. When the user switches back to the Unity application, the GameObjects receive an OnApplicationFocus call with the argument set to true.
You could implement this with the gameobjects you want to continue behaving as you like.

Is it possible to get screen content from an Android Service

I am trying to create a TV back light controller that runs on Android TV. To do this I want to use what is being displayed and adjust the back light colors accordingly. I am having trouble determining a good way to basically get a screenshot regularly through a service. Does anyone have any ideas?
On Android 5.0+, you can use the media projection APIs for this. However:
The user has to authorize this, by launching one of your activities which then displays a system-supplied authorization dialog
That authorization does not last forever, but only for however long your process is around (and possibly less than that, though so far in my testing it seems to last as long as the process does)
AFAIK, DRM-protected materials will be blocked from the screenshots, and so using those screenshots to try to detect foreground UI colors may prove unreliable

Is it possible to check in background if an android/iOS device is in use at the moment?

Is it possible to determine if a device (non-rooted) is in use at the moment, even if my app is not in the foreground? Precisely "in use" means the user made touch events in the last 5 seconds or display is on.
If so, what specific rights are required?
Thanks
AFAIK, android security model would not allow you to record touches if your app in not in the foreground.
There are some crude workarounds like overlaying a transparent screen to record touches. Not sure if these work now though.
"in use" means the user made touch events in the last 5 seconds
In Android, that's not practical, short of writing your own custom ROM.
or display is on
In Android, you can find out if the device is in an "interactive" mode or not. This does not strictly align with screen-on/screen-off, as the whole notion of screen-on/screen-off has pretty much fallen by the wayside.

Make Android Screen never dim while on a particular activity?

Going through logs from 2009, it seems that everyone was complaining that this wasn't an option.
Now all I'm finding is people telling people different ways to do it, none of which work on my device. keepScreenOn, or its corresponding flag in LayoutParams, only serves to keep the screen on, even though multiple people have offered it as a solution for screen dimming.
WakeLocks, on the other hand (as I have seen them demonstrated online, anyway), appear to do absolutely nothing, not even keep the screen alive. The screen dims at the normal time, and I even get to see this hilarious little number on the monitor I have running on my laptop:
02-04 00:10:30.687: D/PowerManagerService(192): #PowerManagement: 'MyActivitiyName' releaseWakeLock when screen locked
I made sure to follow all the wakelock instructions on this page: http://blog.blundell-apps.com/tut-keep-screen-onawake-3-possible-ways/
There were no build errors, and no runtime errors, either. The screen just dims and then shuts off, in the standard time frame.
Help?
Try by adding following statement in onCreate() method. Hope this will work.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Okay, I was being dumb about the flags, following tutorials too blindly. I assumed the example wakelock flag was supposed to make the screen not dim, but it was the opposite. I switched the wakelock flag to
PowerManager.SCREEN_BRIGHT_WAKE_LOCK
and moved the wakelock acquire and release to onCreate and onDestroy, and now it does what I want.
(to be clear, this does what I want because the current activity is the final state I need for my demo; onDestroy should be called whenever I would possibly want to pause the activity)

Does number of Activities matter in Android App?

I am developing an Android app. I have already crossed more than 20 Activities. So I am bit concerned about it. I mean if there are more Activities in an Android app, does it affect the performance of App like Speed, Memory or any other issue?
Though it is not a standard question but still I feel its something which might help others too
Yes Suraj more activities will affect performance
An activity is the equivalent of a Frame/Window in GUI toolkits. It takes up the entire drawable area of the screen (minus the status and title bars on top). Activities are meant to display the UI and get input from the user
An Activity (calling-Activity) can spawn another Activity (sub-Activity) in 2 ways:
Fire and forget – create an event (Intent) and fire it
Async callback – create an event (Intent), fire it, and wait for it’s response in a callback method (of the calling-Activity).
So the effect of activities will depend on performance of your device, its processor and memory etc.
Even if any activity will remain in stack and not finish then it affects device performance.
Even you have to take a look at security measures.

Categories

Resources