解锁设备后的ANR



我正在开发一个使用大量RAM的指纹传感器应用程序,问题可能与内存有关,我尝试了很多仍未解决的问题。

Q:-当我按下主页按钮时,应用程序暂停,并从最近的按钮成功恢复,但当我按下电源按钮然后解锁我的设备时,它显示ANR,而不是我的应用程序屏幕。

这意味着解锁设备时不会恢复。

如果你理解我的观点,请提出建议或给出解决方案。

注意:使用过的设备专用于我的应用程序,不会安装或运行其他应用程序

也许您需要广播接收器来打开或关闭屏幕。

public class ScreenReceiver extends BroadcastReceiver {
    // thanks Jason
    public static boolean wasScreenOn = true;
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            // do whatever you need to do here
            wasScreenOn = false;
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            // and do whatever you need to do here
            wasScreenOn = true;
        }
    }
}

在你的活动中,它将像这个

public class ExampleActivity extends Activity {
   @Override
    protected void onCreate() {
        // initialize receiver
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        BroadcastReceiver mReceiver = new ScreenReceiver();
        registerReceiver(mReceiver, filter);
        // your code
    }
    @Override
    protected void onPause() {
        // when the screen is about to turn off
        if (ScreenReceiver.wasScreenOn) {
            // this is the case when onPause() is called by the system due to a screen state change
            System.out.println("SCREEN TURNED OFF");
        } else {
            // this is when onPause() is called when the screen state has not changed
        }
        super.onPause();
    }
    @Override
    protected void onResume() {
        // only when screen turns on
        if (!ScreenReceiver.wasScreenOn) {
            // this is when onResume() is called due to a screen state change
            System.out.println("SCREEN TURNED ON");
        } else {
            // this is when onResume() is called when the screen state has not changed
        }
        super.onResume();
    }
}

相关内容

  • 没有找到相关文章

最新更新