简体   繁体   中英

Black screen when pressing Home button

I get a weird bug after restart, when i turn screen off and on, pressing the home button results in black screen and i need to restart to have control over my phone again.

I am using a BroadcastReceiver to know when the screen goes off and on to do some logic.

public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals("android.intent.action.SCREEN_OFF")) {
            if (context.getSharedPreferences(Constant.SETTING_PREFERENCE, 0)
                    .getBoolean(Constant.SETTING_LOCKSCREEN_STATUS, false)) {
                Intent intent1 = new Intent(context, LockScreenActivity.class);
                intent1.addFlags(0x10000000);
                context.startActivity(intent1);
            }

        } else {
            if (intent.getAction().equals("android.intent.action.SCREEN_ON")) {
                if (context
                        .getSharedPreferences(Constant.SETTING_PREFERENCE, 0)
                        .getBoolean(Constant.SETTING_LOCKSCREEN_STATUS, false)) {
                    (new Intent(context, TestActivity.class))
                            .addFlags(0x10000000);
                }
                return;
            }
            if (intent.getAction().equals(
                    "android.intent.action.BOOT_COMPLETED")) {
                if (context
                        .getSharedPreferences(Constant.SETTING_PREFERENCE, 0)
                        .getBoolean(Constant.SETTING_LOCKSCREEN_STATUS, false)) {
                    Intent intent2 = new Intent(context,
                            TestActivity.class);
                    intent2.addFlags(0x10000000);
                    context.startActivity(intent2);
                }
                return;
            }
        }

I can sometimes reproduce this bug and from logcat i can see: Waited long enough for: ServiceRecord but the service is running. Not sure how to tackle this situation.

You created this intent but didn't start it. This code has no effect:

                (new Intent(context, TestActivity.class))
                        .addFlags(0x10000000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM