开发者

Prevent locking on custom Android app

开发者 https://www.devze.com 2023-02-16 04:08 出处:网络
What code would you use to prevent the Droid from locking on an app? I am writing an app 开发者_高级运维that uses sockets, and it is essential that the screen not lock in the middle of the app\'s exec

What code would you use to prevent the Droid from locking on an app? I am writing an app 开发者_高级运维that uses sockets, and it is essential that the screen not lock in the middle of the app's execution.


Turn Off Screen Lock by adding the following against the Activity in your AndroidManifest.xml

android:keepScreenOn="true" 

The screen will remain on and be cautious of using this as the display being kept on could impact your battery usage in you Application.


You need a wake lock, obtained from the Power Manager.


I'm not entirely sure what you mean. But I took it to be an unresponsive UI. So if that assumption is correct threading is your answer, do your socket work in here so the UI does not "lock-up"

new Thread(new Runnable(){
    @Override
    public void run(){ 
        Code Here ....
    }
}).start();

Keep in mind also that if you have strange exceptions about modifying UI elements from this thread the Looper can sometimes be useful. http://developer.android.com/reference/android/os/Looper.html

0

精彩评论

暂无评论...
验证码 换一张
取 消