WakefulBroadcastReceiver亮屏后如何跳转到特定activity?

How to go to particular activity after the screen is turned on using WakefulBroadcastReceiver?

我想在使用 WakefulBroadcastReceiver 打开屏幕后转到特定的 activity。屏幕正常点亮,但之后没有任何动作,甚至没有任何异常显示。

以下是我的代码。

AndroidManifest.xml

<uses-permission android:name="android.permission.WAKE_LOCK" />
<receiver android:name=".Alarm" />

Java 文件

public class Alarm extends WakefulBroadcastReceiver {

    @Override
        public void onReceive(Context context, Intent intent) {

        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT_WATCH) {
            isScreenOn = powerManager.isInteractive();
        }
        else
        {
            isScreenOn = powerManager.isScreenOn();
        }
        if(!isScreenOn)
        {
            PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"Remind Me");
            wakeLock.acquire();
            Intent gotoIntent;
            gotoIntent = new Intent(context, MainActivity.class);
            gotoIntent.putExtra(ReminderActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
            context.startActivity(gotoIntent);
        }
}

我自己的问题得到了完美的答案: 我只需要在创建 intent

时使用 gotoIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    Intent gotoIntent;
    gotoIntent = new Intent(context, MainActivity.class);
    gotoIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    gotoIntent.putExtra(ReminderActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
    context.startActivity(gotoIntent);