如果屏幕锁定设置为无ViewFlipper不会重新启动翻转 [英] ViewFlipper does not restart flipping if Screen Lock is set to None

查看:1025
本文介绍了如果屏幕锁定设置为无ViewFlipper不会重新启动翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 ViewFlipper同样的问题不会重新启动翻转如果屏幕锁定设置为无

在ViewFlipper控件的一个很酷的功能是,它会自动停止翻转时,屏幕熄灭,然后重新启动翻转,如果它继续下去。

A cool feature of the ViewFlipper widget is that it automatically stop flipping when the screen goes off, and restart flipping if it goes on.

不幸的是,如果没有屏幕锁设置(设置>安全>屏幕锁定>无)的Intent.ACTION_USER_ preSENT从不广播系统,并且ViewFlipper无法重新启动(永远)。

Unfortunately, if no screen lock is set (Settings > Security > Screen Lock > None) the Intent.ACTION_USER_PRESENT is never broadcasted to system, and ViewFlipper cannot be restarted (ever).

可能的修补程序是:

一)重新启动ViewFlipper翻转上ACTION_SCREEN_ON而非ACTION_USER_ preSENT。
二)广播ACTION_USER_ preSENT如果没有锁屏设置和屏幕不胜枚举。

a) restart ViewFlipper flipping on ACTION_SCREEN_ON rather than ACTION_USER_PRESENT. b) broadcast ACTION_USER_PRESENT if no screen lock is set and screen goes on.

步骤来重现错误:


  • 设置屏幕锁定为无系统设置。

  • 使用ViewFlipper启动的应用程序。

  • 设置屏幕关闭(上电快速preSS)

  • 设置在屏幕上(上电快速preSS)

结果:ViewFlipper不再是动画

Result: the ViewFlipper is no more animated

预期的结果:在ViewFlipper必须再次动画

看来,这个问题一直没有得到解决。我想解决它在我自己的应用程序。有什么办法呢?

It seems that this issue hasn't been solved. I wanna fix it in my own app. is there any ways?

我试图解决这个问题。我给广播 Intent.ACTION_SCREEN_ON 在我的code。但它抛出异常:

I tried to solve it. I sent the broadcaster Intent.ACTION_SCREEN_ON in my code. But it throw Exception:

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.USER_PRESENT from pid=XXX, uid=XXX

然后我检查了源$ C ​​$ C发现这些广播仅由系统。失败了。

Then I checked the source code found these broadcasters are only used by system. Failed.

推荐答案

您可以试试这个,它应该工作:

You can try this, it should work:


  • 在您的活动中取出的每startFlipping()或stopFlipping()或setAutoStart()或setFlipInterval()。

  • Remove every startFlipping() or stopFlipping() or setAutoStart() or setFlipInterval() in your activity.

现在添加到您的活动:

code:

private boolean isStarted = false;

private void runFlipper() {
    if (isStarted == false) {
        Message msg = mHandler.obtainMessage(42);
        mHandler.sendMessageDelayed(msg, 3000);
        isStarted = true;
    }
}

private void stopFlipper() {
    mHandler.removeMessages(42);
    isStarted = false;
}

@SuppressLint("HandlerLeak")
private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        if (msg.what == 42) {
            Log.d("ImageFlipper", "Next picture...");
            viewFlipper.showNext();
            msg = obtainMessage(42);
            sendMessageDelayed(msg, 3000);
        }
    }
};

(viewFlipper是viewFlipper =(ViewFlipper)this.findViewById(R.id.view_flipper);)

("viewFlipper" is viewFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);)


  • 在活动的onResume()调用runFlipper()。

  • 在活动的的onPause()调用stopFlipper()。

如果一切正常,不要忘记清洁code;)

If it works, don't forget to clean the code ;)

private static final int DELAY_MSG = 42;
private static final int DELAY = 3000;

这篇关于如果屏幕锁定设置为无ViewFlipper不会重新启动翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆