Android解锁后黑屏

Android Black Screen after Unlocking

我在锁定设备屏幕后无法恢复应用 activity。

典型情况如下:

1. App is running.
2. Lock device.
3. Unlock device.
4. Instead of returning to running app, it shows a black screen.

我检查了 activity 生命周期是怎样的 运行 似乎这就是它解锁时发生的事情:

1. Create
2. Start
3. Resume
4. Pause

为什么一直卡在暂停状态?我敢肯定这真的很简单,但是因为我还在学习 Android 我非常困惑。感谢您提供的任何帮助!


编辑:

我认为我没有做任何不寻常的事情,但这是我正在使用的基本代码...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.i("Java", "Create");

    // Initialize NDK audio properties here

    // Initialize the Content View
    setContentView(R.layout.activity_main);

    // Setup toolbar
    Toolbar myToolbar = (Toolbar) findViewById(R.id.toolBar);
    setSupportActionBar(myToolbar);

    // Start thread
    thread = new Thread() {
        public void run() {
            setPriority(Thread.MAX_PRIORITY);
            // Audio Thread is running here
        }
    };
    thread.start();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
}

@Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onPause() {
    super.onPause();
    if (thread != null) {
        try {
            thread.join();
        }
        catch (InterruptedException e) {
            // e.printStackTrace();
        }
        thread = null;
    }
}

@Override
protected void onResume() {
    super.onResume();
}

@Override
protected void onStop() {
    super.onStop();
}

试试这个(它会指示您的应用保存状态):

protected void onSaveInstanceState(Bundle icicle) {
    icicle.putLong("param", 1);
    super.onSaveInstanceState(icicle);
}

我不是线程专家。但在这里您似乎在暂停时阻塞了 ui 线程。 thread.join 导致当前线程(在本例中为 ui 线程)暂停执行,直到线程终止。