0

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

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

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

如果您明白我的意思,请提出建议或提供解决方案。

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

4

1 回答 1

0

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

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();
    }

}
于 2015-02-26T06:22:29.377 回答